Skip to content

Commit

Permalink
Added: documentation for bool switch (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
signebedi committed Jul 1, 2024
1 parent 560e6ae commit 8f22fa4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ In addition to the basic input types described above, the form configuration sup
First, `hidden` fields are used to store data that should not be visible or editable by the user. They are often used to hold metadata or other values that need to be submitted with the form but should not be altered by the user. This field comes with the `secondary_input_type` parameter, which defaults to "hidden" and defines an alternative input type to use when the form is being updated. This allows hidden fields to be shown as editable fields during updates if necessary.

Additionally, `immutable_config` fields display data that should not be modified by the user but may be linked to context variables such as request.user or config.SITE_NAME. These fields can be set to be both mutable (eg. update some user value based on a later editor) or hidden under certain conditions. This field comes with various additional parameters. The `context_field` parameter specifies the context variable to link the field value to, supporting nested context fields like `user.username` or `config.SITE_NAME`. This parameter is required. The `is_hidden` parameter is a boolean that indicates whether the field should be hidden. It is optional and defaults to false. The `update_on_edit` parameter is a boolean indicating whether the field should become editable when the form is being updated. It defaults to false. Similarly, the `update_on_duplicate` parameter is a boolean that specifies whether the field should become editable when the form is being duplicated. This parameter defaults to true.
Second, `immutable_config` fields display data that should not be modified by the user but may be linked to context variables such as request.user or config.SITE_NAME. These fields can be set to be both mutable (eg. update some user value based on a later editor) or hidden under certain conditions. This field comes with various additional parameters. The `context_field` parameter specifies the context variable to link the field value to, supporting nested context fields like `user.username` or `config.SITE_NAME`. This parameter is required. The `is_hidden` parameter is a boolean that indicates whether the field should be hidden. It is optional and defaults to false. The `update_on_edit` parameter is a boolean indicating whether the field should become editable when the form is being updated. It defaults to false. Similarly, the `update_on_duplicate` parameter is a boolean that specifies whether the field should become editable when the form is being duplicated. This parameter defaults to true.

Third, `bool_switch` fields represent a boolean switch, commonly implemented as a toggle switch with true or false values. The behavior of this input type includes additional parameters and a specific handling of the `default` parameter. The `true_label` and `false_label` parameters are optional and define the labels displayed for the "on" and "off" states of the switch, respectively. They default to "true" and "false" if not provided. The `default` parameter for `bool_switch` works differently compared to other input types. Instead of directly using the default value, it determines whether the switch should be in the "on" or "off" position. If `default` is provided and evaluates to `true`, the switch will be in the "on" position; otherwise, it will be in the "off" position. Passing no value as the `default` will result in it defaulting to `false`.


##### Using YAML Tags
The custom loader supports specific YAML tags to define output types and dynamically retrieve data for select, radio, and checkbox fields in forms. These include output_type tags indicating the expected type of a field's output.
Expand All @@ -183,6 +186,7 @@ The custom loader supports specific YAML tags to define output types and dynamic
- !list: List value.
- !tuple: Tuple value.
- !bytes: Byte value.
- !bool: Boolean value,

These also include data retrieval tags that dynamically yield data for form fields such as select, radio, and checkbox inputs.

Expand Down

0 comments on commit 8f22fa4

Please sign in to comment.