ผลต่างระหว่างรุ่นของ "CuneiTable"
(→Define) |
|||
บรรทัดที่ 30: | บรรทัดที่ 30: | ||
=== The Holy Trinity of CuneiTable === | === The Holy Trinity of CuneiTable === | ||
The 3 MASTER variables listed below are '''''required''''' for all CuneiTable classes. | |||
* '''{{code|MASTER_colnames}}''' ''([str,])'': The list of column headers to appear on the page. | |||
* '''{{code|MASTER_coltypes}}''' ''([str,])'': The list of column value types. Available types include: | |||
** All types listed in the main article for [[CuneiForm#Available Types|CuneiForm]]. | |||
** '''{{code|lang=python|'str'}}''': Normal ''string'' value. | |||
** '''{{code|lang=python|'check'}}''': Value represented by a checkbox. | |||
** '''{{code|lang=python|'sel'}}''': Value with multiple choices. In other words, this is equivalent to a ''drop-list field'' in forms. In the same fashion, the displayed values for this type is not exactly the same as the values stored in the database. The raw value must pass through a map first before being displayed. | |||
** '''{{code|lang=python|'rad'}}''': Similar to {{code|lang=python|'sel'}}, but this value type is represented by a radio buttons in multiple sub-columns instead. | |||
=== Table with a Separate Form Modal === | === Table with a Separate Form Modal === |
รุ่นแก้ไขเมื่อ 07:17, 17 เมษายน 2567
CuneiTable is designed specifically to enable in-line data entry. Design-wise, it is more limited than CuneiForm since design flexibility is not highly expected from table-rype objects. In essence, CuneiTable is a wrapper for the accompanying CuneiForm, whether that form be the in-line type or the full expansion type.
Define
Defining a CuneiTable is essentially declaring a CuneiForm with a few additional class variables. Below is an example of a very basic CuneiTable:
class AccCodeTable(CuneiTable):
MASTER_colsizes = [10, 20, 50, 20]
MASTER_colnames = ["StID", "Account Code", "Account Name", "Account Group"]
MASTER_coltypes = ["int", "str", "str", "sel"]
MASTER_choicecols = ["accgrp"]
MASTER_choices = [[
("1", "1: Asset"),
("2", "2: Liability"),
("3", "3: Equity"),
("4", "4: Revenue"),
("5", "5: Expense")
]]
MASTER_firstonly = ["stid"]
class SubForm(FlaskForm, CuneiSubForm):
stid = StringField("StID")
code = StringField("Code", validators=[InputRequired("Required!")])
name = StringField("Name", validators=[InputRequired("Required!")])
accgrp = SelectField("Group", default=1)
def validate_stid(self, stid):
# Validation goes here
The subclass SubForm is defined like the stripped down version of CuneiForm. Only put fields and validation logics here. All other behaviours are controlled by the MASTER variables from the CuneiTable level.
The Holy Trinity of CuneiTable
The 3 MASTER variables listed below are required for all CuneiTable classes.
MASTER_colnames
([str,]): The list of column headers to appear on the page.MASTER_coltypes
([str,]): The list of column value types. Available types include:- All types listed in the main article for CuneiForm.
'str'
: Normal string value.'check'
: Value represented by a checkbox.'sel'
: Value with multiple choices. In other words, this is equivalent to a drop-list field in forms. In the same fashion, the displayed values for this type is not exactly the same as the values stored in the database. The raw value must pass through a map first before being displayed.'rad'
: Similar to'sel'
, but this value type is represented by a radio buttons in multiple sub-columns instead.
Table with a Separate Form Modal
Making a table with fullform? You can stop this section here.