Can I trigger "postCreate" for a record not created by Editor?

Can I trigger "postCreate" for a record not created by Editor?

tangerinetangerine Posts: 3,341Questions: 35Answers: 394
edited March 2022 in Editor

For some of my tables, records are created through my own PHP controller/model set-up. The Editor files are referenced throughout, but the "Create" button is not presented to the user.
I now realise that it would sometimes be useful to hook into the Editor's "postCreate" function from my PHP. Is that possible - perhaps by access to Editor::ACTION_CREATE, for instance?

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,787Questions: 85Answers: 404
    edited March 2022

    I don't think so, but let @allan or @colin check it out for your, tangerine.

    If they can't help you there could be this work around. Even without showing the "Create" button to the user you can always trigger record creation using Editor from the front end like in here:
    https://datatables.net/forums/discussion/comment/204784#Comment_204784

    The example is about "editing" but "creating" works the same way ...

  • tangerinetangerine Posts: 3,341Questions: 35Answers: 394

    Thank you! I'll check your code out later.

  • allanallan Posts: 61,038Questions: 1Answers: 9,953 Site admin
    Answer ✓

    It depends a bit what you want to get out of postCreate. Like, do you use the parameters passed to it? This is where it gets called, so while there isn't a way to trigger it outside of Editor, you could call a named function - e.g.:

    function doSomething ( ... ) {
    
    }
    
    // Later
    ->on('preCreate', function ( $id, $values, $row ) {
      doSomething( ... );
    } )
    
    // And elsewhere
    doSomething( ... );
    

    Again, it really comes down to the parameters that you need and what you have access to in this other location where you need to perform the postCreate action.

    Allan

  • tangerinetangerine Posts: 3,341Questions: 35Answers: 394

    Thanks, Allan. I need to think this through again. It's begun to look like a fresh can of worms. I may come back from a different direction, as related problems have turned up. Oh woe.
    Thanks again.

Sign In or Register to comment.