How to disable/enable Update button on Edit Entry form

How to disable/enable Update button on Edit Entry form

peiwaipeiwai Posts: 6Questions: 2Answers: 0
edited February 2023 in Free community support

I need to enable/disable the Update button on Edit Entry form base on the user access right.

I have looked at the documentation: https://editor.datatables.net/reference/option/i18n
but it doesn't include the code to disable/enable those buttons on the popup entry forms for Create, Edit, Delete.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    button().enable() and button().disable() are the two methods that you can use to enable and disable buttons. However, even better would be to not show the buttons that the user doesn't have access rights to. For that, you would need to either dynamically generate the Javascript that defines the buttons, or have the access right information available in Javascript, allowing you to decide if the buttons should be added or not.

    Allan

  • peiwaipeiwai Posts: 6Questions: 2Answers: 0

    I tried to apply button.disable() functions on the editor table as below, hoping the function will disable the Update button on the editor form but it generates error: "editor.button is not a function".

    var editor = new $.fun.dataTable.Editor({
    ajax: "[%request.uri_base;%]"/route1",
    table: "table1",
    idSrc" "column1",
    fields:[
    { name: "field1"}]
    });
    editor.button(0).disable();

    The purpose of allowing the non admin users to view the form so they can get trained and eventually be granted the admin permission.

  • peiwaipeiwai Posts: 6Questions: 2Answers: 0

    The code above should be:

    var editor = new $.fun.dataTable.Editor({
    ajax: "[%request.uri_base;%]"/route1",
    table: "table1",
    idSrc" "column1",
    fields:[
    { name: "column1"}]
    });
    editor.button(0).disable();

  • colincolin Posts: 15,146Questions: 1Answers: 2,586
    edited February 2023

    I see you're using Editor in your example, but our accounts aren't showing that you have a license. Is the license registered to another email address? Please can let us know so we can update our records and provide support.

    Thanks,

    Colin

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin
    Answer ✓

    In addition to Colin's question - do you mean the buttons inside the Editor modal? I had thought you meant the buttons that trigger the editing in the first place.

    I'm afraid there isn't an API to allow the buttons inside the modal to be disabled at this time. I thought about it because but I then imagined my own frustration if I filled in the form to then find there was no way to submit it!

    However, if you want to allow that, then you could use preSubmit to cancel the edit (which would handle return key submission of the form as well as the buttons). e.g.:

    editor.on('preSubmit', function () {
      alert('You do not have submit permissions');
      return false;
    });
    

    Of course that is trivial to bypass client-side - you'd need to make sure the server also enforced the permissions correctly.

    Allan

  • peiwaipeiwai Posts: 6Questions: 2Answers: 0

    Yes, our company has license for Editor extension. I am signing in using my personal account.
    That is right Allan, I mean the editor modal, the popup entry screen. I can see your point if the button can be disabled, then there is no way to submit the form. In that case, users could click on the x button to close the modal. The options you provided are useful. Thank you.

Sign In or Register to comment.