Show formButtons conditionally

Show formButtons conditionally

hnhegdehnhegde Posts: 68Questions: 17Answers: 0

Hello,
Consider following formButtons:
formButtons: [ { text: 'Cancel', action: function () { this.close(); }, }, 'Delete', ],
Is there a way to show 'Delete' button only if a certain condition applies?

Thanks,
Harsha

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @hnhegde ,

    My last example on this thread should help - it's not showing/hiding, but enabling/disabling, but the same principle would apply.

    Cheers,

    Colin

  • hnhegdehnhegde Posts: 68Questions: 17Answers: 0

    Hi @colin ,
    That example doesn't seem to be working. 'Create' button is enabled all the time.
    Is there a way I can reinitialise formButtons after the form has opened?

    Regards,
    Harsha

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @hnhegde ,

    This was the example here - it disables the Edit's update button when the office field is empty (my description when a bit wonky on the other thread).

    I modified it here so that in the same Edit scenario, it's removing the button. Hope that helps.

    Is there a way I can reinitialise formButtons after the form has opened?

    I don't believe so, the buttons are created when the form is opened.

    Cheers,

    Colin

  • hnhegdehnhegde Posts: 68Questions: 17Answers: 0

    Hi @colin ,
    That was helpful. I am going to trick you a bit more :smile:
    What if there are two buttons and I want to hide only one. Please refer to this example.
    If Office is empty, can I keep the 'Cancel' button and hide 'Update'?
    Regards,
    Harsha

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Yep, you can use a selector for that - see here.

    C

  • hnhegdehnhegde Posts: 68Questions: 17Answers: 0

    That worked! Thanks @colin Much appreciate your quick response!

    Regards,
    Harsha

This discussion has been closed.