Set focus on field

Set focus on field

GG Posts: 16Questions: 7Answers: 0

Hello Allan,

Using DataTables Editor plugin.
If there a way to set focus on a specific field?

I have four field:
1. Field1 (optional)
2. Field2 (Required) <- I want the focus to come here by default. when editor opens
3. Field3 (Required)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Yes - you can use the focus option of the form-options object, which you can define using formOptions.main or when you call edit() if you are calling it directly.

    Allan

  • GG Posts: 16Questions: 7Answers: 0

    Thanks Allan

  • Lucho_1312Lucho_1312 Posts: 30Questions: 9Answers: 0

    Hi! Is there a way to choose the focus but in when opening the editor through the "Add" button?

    It works for me when something is calling edit(), but not when calling create :(

    Thanks!

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    opening the editor through the "Add" button?

    What "Add" button? Can you link to the page please?

    Allan

  • GG Posts: 16Questions: 7Answers: 0

    Allan,

    editor.field(FIELDNAME).focus();
    works fine.
    But, we how do I change it based on editor action.

    So, If its "ADD" / "CREATE" new record
    Need focus on different field

    While "EDIT" record, need focus on different field.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    You can use the focus option of the form-options parameter. Or alternatively listen for the open option which will tell you what action is being performed and you can then execute the focus() method.

    Allan

This discussion has been closed.