Trick to add button/link on edit form to launch other action

Trick to add button/link on edit form to launch other action

bfarkasbfarkas Posts: 181Questions: 48Answers: 0

Trying to add a link or button under a specific field on the create/edit form that would launch a button action from the main button menu, I have that action working elsewhere, but it will not work anyway I try once it is in the form. Is there a trick to getting those actions to read back to the p200table/editor?

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    Use an event handler, e.g. on "open" or on "opened", to trigger your button click on the main menu button.

    https://editor.datatables.net/reference/event/open
    https://editor.datatables.net/reference/event/opened

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    Unless I’m misunderstanding I don’t think that would work. That would trigger it as the form is opening no? The goal is to add the link next to a field on the form, currently using the message option, so that a user can click it if they wish, which would close the form and launch the modal from the other button.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Trying to add a link or button under a specific field

    I'd use the field.fieldInfo option for that. It can take HTML so you could do:

    fieldInfo: '<a ...>...</a>'
    

    Then if you want to base a Javascript action on that, give the link a specific class and add an event listener for that element / class.

    Allan

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    That's kind of what i've been doing, but just using the setup on the link directly:

    <a onclick="jsfunction()" href="javascript:void(0);">
    
  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    I have been using functions that work on other modals, anytime i try to add on the edit form, nothing happens. It feels like something needs to be set or passed or something.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Can you give me a link to a page showing the issue please?

    Thanks,
    Allan

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    Yup, sorry about that, the one server I had left was down all weekend, just uploaded an example here:
    https://newyorklife.acms.com/penp51nfe0mc/

    So it will make you define one Nest initially, once you have you can use the '+' to do a new entry where I have the link in field info to try and launch the nest editor. Nothing happens and nothing is logged in console of use.

    I have the exact same link setup in a modal on the page that works, it is just an informational window though (its actually the modal showing when you first go to that link in blue, and the first link in it that you need to click to launch and define a nest.).

    Thanks!
    Brian

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Could you try replacing:

    "fieldInfo": '<a href="javascript:void(0);" onClick="globaljs.nestWindow(); return false;">Edit nests.</a>',
    

    with:

    "fieldInfo": '<a class="nestWindow">Edit nests.</a>',
    

    And then, just after the Editor initialisation add:

    $('a.nestWindow', editor.field('nest').node()).on('click', function (e) {
      e.preventDefault();
      globaljs.nestWindow();
    });
    

    Thanks,
    Allan

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0
  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    That event handler is running, and the globaljs.nestWindow() does execute.

    It also appears that the .button( '3-0' ).trigger(); code executes, but it isn't replacing the existing modal. Could you now try:

    $('a.nestWindow', editor.field('nest').node()).on('click', function (e) {
      e.preventDefault();
      editor.close();
    
      setTimeout( function () {
        globaljs.nestWindow();
      }, 250);
    });
    

    Thanks,
    Allan

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    That did it, thanks!!
    So you are basically closing the editor modal and then launching the other right?
    Just want to make sure I am understanding so I can build others.

This discussion has been closed.