custom button on editor form

custom button on editor form

montoyammontoyam Posts: 568Questions: 136Answers: 5

The closest thing I could find to add a button on the Editor form is this
https://editor.datatables.net/examples/api/cancelButton.html

but, it's not quite what I am looking for.

I have a select input on the Editor. When they select a value I will want to make a button visible and depending on what they selected, change the text and action of the button.

    RequestHeaderEditor.field('RequestHeader.ActonID').input().on('change', function (e, d) {
        if (d === undefined) {
            // The change was triggered by the end user on update rather than an auto set
            RequestHeaderEditor.hide(['RequestHeader.EndDate', 'RequestHeader.ReplacedUserID'])
            var actionID = RequestHeaderEditor.get('RequestHeader.ActonID');
            switch (actionID) {
                case 1:  //add
                    RequestHeaderEditor.show(['RequestHeader.EndDate', 'RequestHeader.ReplacedUserID'])
                    // show button with caption of 'Next'
                    break;
                case 2: //delete
                    // show button with caption 'Submit'
                    break;
                case 3: //update
                    // show button with caption of 'Next'
                    break;
            }
});

Then, on click of that button, I will do different actions depending on the value of actionID

Is that possible?

This question has an accepted answers - jump to answer

Answers

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

    You could do something like this.

      editor.on('open', function() {
        $('.DTE_Form_Buttons button:eq(1)').hide();
      })
      
      editor.dependent('name', function(val, data, callback) {
        if (val.length === 0) {
          $('.DTE_Form_Buttons button:eq(1)').hide();
        }
        else {
          $('.DTE_Form_Buttons button:eq(1)').show();
          $('.DTE_Form_Buttons button:eq(1)').text('Clear "' + val + '"')
          
        }
        callback(true);
      })
    

    The button is hidden on form load. Then when something is entered into the Name field, the button is displayed with the text of the field.

    Would that work for you?

    Colin

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    i will try that on Monday. Thank you.

    side topic: What is the difference/advantage of using .dependent over using the .on('change') that I posted?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Basically none - that is exactly what dependent() is doing under the hood.

    Allan

Sign In or Register to comment.