Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix hashtag generator with this) #628

Open
github-actions bot opened this issue Nov 13, 2024 · 0 comments
Open

fix hashtag generator with this) #628

github-actions bot opened this issue Nov 13, 2024 · 0 comments
Labels

Comments

@github-actions
Copy link

// default color as it generate hashtags in decidim (TODO: fix hashtag generator with this)

require("formBuilder/dist/form-builder.min.js")
import "src/decidim/decidim_awesome/forms/rich_text_plugin"

window.CustomFieldsBuilders = window.CustomFieldsBuilders || [];

$(() => {
    $(".awesome-edit-config .proposal_custom_fields_editor").each((_idx, el) => {
        const key = $(el).closest(".proposal_custom_fields_container").data("key");
        const configVar = $(el).closest(".proposal_custom_fields_container").data("var");
        // DOCS: https://formbuilder.online/docs
        window.CustomFieldsBuilders.push({
            el: el,
            key: key,
            var: configVar,
            config: {
                i18n: {
                    locale: "fr-FR",
                    location: "https://decidim.storage.opensourcepolitics.eu/osp-cdn/form_builder/1.1.0"
                },
                formData: $(`input[name="config[${configVar}][${key}]"]`).val(),
                disableFields: ["button", "file"],
                disabledActionButtons: ["save", "data", "clear"],
                disabledAttrs: [
                    "access",
                    "inline",
                    "className"
                ],
                controlOrder: [
                    "text",
                    "textarea",
                    "number",
                    "date",
                    "checkbox-group",
                    "radio-group",
                    "select",
                    "autocomplete",
                    "header",
                    "paragraph"
                ],
                disabledSubtypes: {
                    // default color as it generate hashtags in decidim (TODO: fix hashtag generator with this)
                    text: ["color"],
                    // disable default wysiwyg editors as they present problems
                    textarea: ["tinymce", "quill"]
                }
            },
            instance: null
        });
    });

    $(document).on("formBuilder.create", (_event, idx, list) => {
        if (!list[idx]) {
            return;
        }

        $(list[idx].el).formBuilder(list[idx].config).promise.then(function(res) {
            list[idx].instance = res;
            // Attach to DOM
            list[idx].el.FormBuilder = res;
            // remove spinner
            $(list[idx].el).find(".loading-spinner").remove();
            // for external use
            $(document).trigger("formBuilder.created", [list[idx]]);
            if (idx < list.length) {
                $(document).trigger("formBuilder.create", [idx + 1, list]);
            }
        });
    });

    if (window.CustomFieldsBuilders.length) {
        $(document).trigger("formBuilder.create", [0, window.CustomFieldsBuilders]);
    }

    $("form.awesome-edit-config").on("submit", () => {
        window.CustomFieldsBuilders.forEach((builder) => {
            $(`input[name="config[${builder.var}][${builder.key}]"]`).val(builder.instance.actions.getData("json"));
        });
    });
});
@github-actions github-actions bot added the todo label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants