Display field type getting focus

Display field type getting focus

Loren MaxwellLoren Maxwell Posts: 387Questions: 94Answers: 10

For the Display field type (plugin) is there a way to skip over it when the form considers the focus? I've noticed that when the first field is a Display type there appears to be no initial focus on the form.

I'm assuming because the default focus is 0, which ends up being an HTML element.

I understand I can set the focus to a different field, but I was wondering if Editor couldn't see that the field shouldn't get the focus.

I haven't checked, but disabled or hidden fields might have the same concern.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,095 Site admin
    Answer ✓

    Good point. Currently no, there is no way to skip over a field for focus like that. Editor will attempt to set focus on the field that was specified (0 by default as you say). If it can't, no focus will be set. Currently you'd need to set focus on index 1.

    Allan

  • Loren MaxwellLoren Maxwell Posts: 387Questions: 94Answers: 10

    For anyone interested, here's the solution I ended up doing.

    I wanted the form to open and skip field types that cannot accept an entry (display, hidden, and readonly) and also skip fields with a default value.

    In the editor's open event I look for the first field where the canReturnSubmit function is not undefined (or null) and the default value is null to find the first field open for immediate entry.

    This does NOT address the readonly field, which does have a canReturnSubmit function unless it has a default value.

    Seems hackish, especially checking the canReturnSubmit, but it works for what I'm doing.

    @allan, maybe a canReceiveFocus field property would be helpful?

    At any rate:

    editor_sa_conferences = new $.fn.dataTable.Editor({
        "table": "#sa_conferences",
        "formOptions": {
            "main": {
                "onReturn": function (editor, ev) {
                    console.log(ev.ctrlKey);
                }
            },
            "inline": {
                "submit": "allIfChanged",
                "drawType": "none"
            }
        },
        "ajax": {
            "url": "/wiki/extensions/GHSFHA/models/database/m_sa_conferences.php",
            "type": "POST",
            "data": {
                "currentUser": "Loren Maxwell"
            }
        },
        "fields": [{
            "name": "id",
            "def": null,
            "label": "Id",
            "type": "display"
        }, {
            "name": "season_name",
            "def": null,
            "label": "Season"
        }, {
            "name": "organization",
            "def": null,
            "label": "Organization"
        }, {
            "name": "class",
            "def": null,
            "label": "Class"
        }, {
            "name": "conference_name",
            "def": null,
            "label": "Conference name"
        }, {
            "name": "abbrv",
            "def": null,
            "label": "Abbreviation"
        }, {
            "name": "cross_count",
            "def": null,
            "label": "Cross count",
            "type": "checkbox",
            "separator": "|",
            "options": [{
                "label": "",
                "value": 1
            }],
            "unselectedValue": 0
        }]
    }).on('open', function (e, mode, action) {
        if (mode === 'main') {
            var focused = false;
            var i = 0;
            do {
                var fieldname = editor_sa_conferences.fields()[i];
                if (editor_sa_conferences.field(fieldname).canReturnSubmit != null && editor_sa_conferences.field(fieldname).def() == null) {
                    editor_sa_conferences.field(fieldname).focus();
                    focused = true;
                } else {
                    ++i
                }
            } while (!focused && i < editor_sa_conferences.fields().length);
        }
    }).on('open', function (e, mode, action) {
        if (mode === 'main') {
            sa_conferences.keys.disable();
        }
    }).on('close', function () {
        sa_conferences.keys.enable();
    });
    
  • allanallan Posts: 61,665Questions: 1Answers: 10,095 Site admin

    canReceiveFocus

    I like that. Added to my list :)

This discussion has been closed.