Development
This commit is contained in:
parent
96f6e32c8f
commit
5575b06b64
7 changed files with 126 additions and 63 deletions
|
|
@ -362,7 +362,10 @@ def build_form_script(field_specs, submit_sel):
|
|||
checkbox_only.append(vn)
|
||||
else:
|
||||
validate_items.append((vn, nm))
|
||||
gate_vars.append(f'{vn} && {vn}._valid')
|
||||
if spec.get('optional'):
|
||||
gate_vars.append(f'(!{vn} || !{vn}.value.trim() || {vn}._valid)')
|
||||
else:
|
||||
gate_vars.append(f'{vn} && {vn}._valid')
|
||||
|
||||
lines.append('')
|
||||
|
||||
|
|
@ -785,21 +788,22 @@ def build_field(item, tokens):
|
|||
_vmask = parse_validation(validate_raw) if validate_raw else 0
|
||||
validate_attr = f' data-validate="{_vmask}"' if _vmask else ''
|
||||
depends_attr = f' data-depends="{e(",".join(depends))}"' if depends else ''
|
||||
extra_attrs = ''.join(f' {e(ak)}="{e(str(av))}"' for ak, av in item.get('attrs', {}).items())
|
||||
extra_attrs = ''.join(f' {e(ak)}="{e(apply_tokens(str(av), tokens))}"' for ak, av in item.get('attrs', {}).items())
|
||||
optional_attr = ' data-optional="1"' if item.get('optional') else ''
|
||||
existing_ids = apply_tokens(item.get('existing_ids', ''), tokens)
|
||||
existing_attr = f' data-existing-ids="{e(existing_ids)}"' if existing_ids else ''
|
||||
if _vmask:
|
||||
return (
|
||||
f'<div class="form-group"><label class="form-label">{label}</label>'
|
||||
f'<div class="field-wrap"><input type="{e(input_type)}" name="{name}" value="{e(value)}"'
|
||||
f' placeholder="{placeholder}" class="form-input"{readonly}{validate_attr}{depends_attr}{extra_attrs}{existing_attr}/>'
|
||||
f' placeholder="{placeholder}" class="form-input"{readonly}{validate_attr}{depends_attr}{extra_attrs}{optional_attr}{existing_attr}/>'
|
||||
f'<p class="form-hint field-dyn-hint hidden"></p></div>'
|
||||
f'{hint_html}</div>'
|
||||
)
|
||||
return (
|
||||
f'<div class="form-group"><label class="form-label">{label}</label>'
|
||||
f'<input type="{e(input_type)}" name="{name}" value="{e(value)}"'
|
||||
f' placeholder="{placeholder}" class="form-input"{readonly}{validate_attr}{depends_attr}{extra_attrs}{existing_attr}/>'
|
||||
f' placeholder="{placeholder}" class="form-input"{readonly}{validate_attr}{depends_attr}{extra_attrs}{optional_attr}{existing_attr}/>'
|
||||
f'{hint_html}</div>'
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue