[Fixed]-How to disable/enable a button on input empty/full while keeping permissions

1👍

You can do this in many ways, depends on your project setup.

If you’re doing light javascript with no extensive form UI modifications, you can simply drop in a data attribute to your button data-has-perm=0 that defines the initial permission, then on your enabling script just add a check for that permission before you re-enable the buttons.

But if you do extensive form UI modifications, i guess the best way to do this is by creating state objects for all your buttons like for example:

var buttons = {
    '#b1': {'initPerm': 0},
    // in your templates file simply do '#b1': {'initPerm': {% if not can_post %}0{% else %}1{% endif %}' 
}  

and you will have an object that holds all your predefined button states, you then check it on your re-enabling methods.

In both cases, never forget to check for the submitted form’s user permissions on your view or form.

Leave a comment