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

How do I disable field actions on specific fields? #1468

Open
mediagiant opened this issue Oct 24, 2023 · 1 comment
Open

How do I disable field actions on specific fields? #1468

mediagiant opened this issue Oct 24, 2023 · 1 comment

Comments

@mediagiant
Copy link

Description: I want to allow a form to be built that includes REQUIRED default fields. I dont want the user to be able to remove or alter these fields, but should be able to add and alter any additional fields they choose.

I have tried using disabledFieldButtons, which removes them for an entire field type, instead of just a specific field. I also tried using a typeUserEvents, but that didnt work either (my attempts and example below). How do I accomplish this?

var baseform = JSON.parse('[{"type":"text","required":true,"label":"First Name","placeholder":"John","className":"form-control","name":"firstname","access":false,"subtype":"text"},{"type":"text","required":true,"label":"Last Name","placeholder":"Smith","className":"form-control","name":"lastname","access":false,"subtype":"text"},{"type":"text","subtype":"email","required":true,"label":"Email Address","placeholder":"[email protected]","className":"form-control","name":"email","access":false}]');

    var options = {
        showActionButtons: false,
        disableFields: ['autocomplete','button','file','header','starRating','paragraph','hidden'],
        disabledFieldButtons: {
          text: ['remove'], // disables the remove butotn for text fields
          select: ['edit'] // disables the edit button for select fields
        },    
        defaultFields: baseform,
        typeUserEvents: {
                text: {
                    onadd: function (fld) {
                        console.log(fld);
                        var $nameField = $('.fld-name', fld);

                        if (($nameField.val() == "firstname") || ($nameField.val() == "lastname") || ($nameField.val() == "email"))
                            $nameField.prop('disabled', true);

                    }
                }
            }
    };

    var fb = jQuery("#build-wrap").formBuilder(options);

Environment Details:

  • formBuilder Version: 3.8.2
  • Browser: Chrome
  • OS: Win 11
@lucasnetau
Copy link
Collaborator

Await the formBuilder().promise and then remove (or disable) the delete and edit buttons for those fields

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants