Pass a value to editor on preOpen

Pass a value to editor on preOpen

INTONEINTONE Posts: 153Questions: 58Answers: 6

Is there a way to do this. I want to pass a value to editor php class so I can make a custom query before it builds the form thus manipulating some of the returned data before the form is shown.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,237Questions: 1Answers: 10,418 Site admin

    The only way to stall the execution in the event handler would be to make a synchronous call to the server (i.e. Sjax rather than Ajax) since there is no callback for the event handler for you to tell the parent executor when your handler is finished. That is an option but it does lock the browser up while the Sjax call is being made.

    Alternatively can you use the Editor API to update the form elements once an Ajax call has been completed?

    Allan

  • INTONEINTONE Posts: 153Questions: 58Answers: 6

    "Alternatively can you use the Editor API to update the form elements once an Ajax call has been completed"

    Do you have an example of how this can be done?

  • allanallan Posts: 63,237Questions: 1Answers: 10,418 Site admin
    Answer ✓

    Not that is publicly available, but the API methods val() and the update() method offered by some fields will be what you want: http://editor.datatables.net/reference/field/select#Methods .

    For example once you've got the data for the select list you would just do: editor.field( 'myField' ).update( myData );.

    Allan

  • INTONEINTONE Posts: 153Questions: 58Answers: 6
    edited June 2014

    Thank you for your valued response. What I was trying to do was simple have a select pre-filled with the current user when the user is creating a record, so the user would not be able to change the select (ie - only one result is in the list). I thought originally about passing a session var to the server and return the actual user for the select. Though this would have been rudimentary on custom scripts this was too much using editor. then I discovered an event call initCreate so I did this:

     editor.on( 'initCreate', function ( e) {
    editor.field('field_name').update( [{ label: "some_label", value: some_value }] );
    });
    

    of course my my original editor instance that build the select list would have been:

                       {
                label: "Created By:",
                name: "some_field_name",
                type: "select"
    
            }
    

    now all I have to do is save the custom session values as javascript object and pass them to the editor field instance. This is awesome. Coming from a pure php background it does take some time wrapping my head around the idiosyncrasies of editor.

This discussion has been closed.