Disable focus on edit form

Disable focus on edit form

djmm68djmm68 Posts: 20Questions: 7Answers: 0

I need to disable focus on edit form only.

First, I've tried this:

formOptions: { main: { focus: null } }

but that disables focus on both forms (create new record form and edit selected record form). I only want to disable focus on second form (edit selected record).

What options must I use in order to get it?

Thanks in advance!

This question has an accepted answers - jump to answer

Answers

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

    Option 1:

    editor.on( 'initEdit', function () {
      editor.one( 'open', function () {
        // blur the field
        editor.field( 'myField' ).input().blur();
      } );
    } );
    

    Option 2 (a better option): if you are using the edit option you could actually set the form option there using the formOptions object, and that will apply to the edit form only.

    Option 3: if you are using edit() directly, you can pass the form options into that method.

    Allan

  • djmm68djmm68 Posts: 20Questions: 7Answers: 0

    Hi Allan, thanks for your reply!

    I really consider the second option as the better too, but I'm struggling about how to apply it.

    Now, I've tried to config it on buttons, so:

        new $.fn.dataTable.Buttons( table, [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor, formOptions: { main: { focus: null } } },
            { extend: "remove", editor: editor }
        ] );
    

    But it seems not to have any result :neutral:

    How should I do it?

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

    I've embarrassed myself here. Option 2 isn't currently possible with the Editor code base as it stands. I had thought that was something I had implemented (was utterly convinced of it!) but looking at the code, only a sub-set of the form options are currently implemented as options for the button.

    I'll look into the best way to address that (and make Editor work the way I thought it was!), but perhaps option 1 might be a workaround for now.

    Allan

  • djmm68djmm68 Posts: 20Questions: 7Answers: 0

    Ok Allan, I understand.

    I'll try to do it with first option.
    Thank you for your help.

    Regards
    Jose

This discussion has been closed.