{% extends "admin/cms/page/plugin/change_form.html" %} {% load i18n %} {% block after_field_sets %}

{% translate "Help for activating Javascript" %}

{% translate "Description of how to set up javascript for form control." %}

{% translate "The settings for form fields when the page loads are defined in the attribute" %} data-init-field-state.

{% translate "Field value format:" %}

{
    "field_name": [action, ...]
}

{% translate "List of values" %} action:

{% translate "The field name can also include the field value. This is necessary for radio buttons or a group of checkboxes. The field value is given in square brackets." %} {% blocktranslate %}For example, agreement[yes] sets the field <input type="radio" name="agreement" value="yes">.{% endblocktranslate %}

{% translate "Example" %}:
const initState = {
    send_to: ["disable", "optional"],
    confirmation_method: ["disable"],
    handle: [{set: "MY HANDLE"}],
    "agreement[yes]": [{set: true}],
}
const config = JSON.stringify(initState)

{% blocktranslate trimmed %} Put the value config in the data-init-field-state attribute. This will disable the send_to and confirmation_method fields in the form when the page loads. The send_to field is set to optional. The handle field is set to "MY HANDLE". The agreement checkbox is checked with the value yes. {% endblocktranslate %}


{% blocktranslate %}Event settings for form fields are defined in the data-add-field-events attribute.{% endblocktranslate %}

{% translate "Field value format" %}:
{
    "trigger_field_name": {
        "event_name": {
            "destination_field_value": [
                {"destination_filed_name": [action, ...]}
            ]
        }
    }
}

{% translate "Example" %}:
const data = {
    send_to: {
        change: {
            custom_email: [
                {confirmation_method: ["enable", "required", {set: "notarized_letter"}]},
                {"agreement[yes]": [{set: true}]},
            ],
            email_in_registry: [
                {confirmation_method: ["disable", "optional"]},
                {"agreement[yes]": [{set: false}]},
            ]
        }
    },
    "policy[confirm]": {
        change: {
            true: {"message": [{set: "Thank you."}]},
            false: {"message": [{set: "Please, check the checkbox."}]},
        }
    }
}
const config = JSON.stringify(data)

{% blocktranslate trimmed %} Put the config value in the data-add-field-events attribute. This will cause the confirmation_method field to be activated when the send_to field is set to custom_email, making it mandatory and setting its value to "notarized_letter". The agreement checkbox is also checked with a value of yes. The confirmation_method field is deactivated and made optional when the send_to field is set to email_in_registry. The agreement checkbox is cleared with a value of yes. {% endblocktranslate %}

{% translate "The current configuration can be saved in readable form with the command" %}:

JSON.stringify(JSON.parse(document.querySelector("[data-init-field-state]").dataset.initFieldState), null, 2)
JSON.stringify(JSON.parse(document.querySelector("[data-add-field-events]").dataset.addFieldEvents), null, 2)

{% translate "Script debugging can be enabled with the url parameter ?debug=true." %}

{% endblock %}