How to set the title / message of the editor form via the editor api?

How to set the title / message of the editor form via the editor api?

pingcrosbypingcrosby Posts: 29Questions: 4Answers: 1
edited January 2017 in Free community support

I am trying to use the editor api to simply set the title and message during edit/create.
No errors are shown. But the form is not displaying the text.

Obviously I am misusing the API but I cannot quite see where i have gone wrong.

Can anyone help me ..

Thanks in advance

cpdHoursEditor = new $.fn.dataTable.Editor({ ... });
cpdHoursTable = $('#cpdHoursTable').DataTable({ ... });

// this does nothing
cpdHoursEditor.title('My Edit Title').buttons('edit');
cpdHoursEditor.title('My New Title').buttons('create');

// this sets the message the first time the editor form is displayed.. after that no message is displayed
cpdHoursEditor.message("mymessage").buttons("edit)

Answers

  • allanallan Posts: 63,839Questions: 1Answers: 10,518 Site admin

    It will work, but it will then be overridden when the editor is activated by the New, Edit, etc buttons.

    Use the internationalisation options for Editor to customise the titles and buttons for when the Buttons are activated.

    If you prefer to use the API methods, use then in initEdit etc.

    Allan

  • pingcrosbypingcrosby Posts: 29Questions: 4Answers: 1
    edited January 2017

    Brilliant thanks for this..

    Sorry i missed it in the documentation.

    Is the API inconsistent :smile: ?? -

    There seems to be no 'message' API within i18n.

    i18n: {
             create: {
                    button: "button text works",
                    submit: "submit button works",
                    title: "title works",
                    message: 'the message does not work'
                }
    }
    

    For the on init event there seems to be no title() api call.

    editor.on('initEdit', function () {
            editor.title('this does not work for me);
    });
    

    To get both the title and message form functionality i have needed to use a combintation of both i18n and the initEdit api?

  • allanallan Posts: 63,839Questions: 1Answers: 10,518 Site admin

    There seems to be no 'message' API within i18n.

    No, because the message is generally assumed to be dynamic unlike the other strings which are generally static (i.e. don't change).

    For the on init event there seems to be no title() api call.

    It does, but it is then more-or-less immediately overwritten by the title works since the title is set by Editor after initEdit. Instead what you could do is use open:

    editor.on('open', function (e, mode, action) {
      if ( action === 'edit' ) {
            editor.title('this does work for me');
      }
    });
    

    Allan

This discussion has been closed.