Editor - standalone - inline.How to get access to all editable fields and not only to the edited one

Editor - standalone - inline.How to get access to all editable fields and not only to the edited one

Tester2017Tester2017 Posts: 145Questions: 23Answers: 17
edited March 2018 in Editor

I am using inline edit with a standalone editor. There are 6 fields that can be edited. Before submitting any changes to the server I will perform field validation on the client side. This sounds easier than it happens, because in the preSubmit only the last edited field will be available. I was looking for some kind of API function to get this field name. I could not find anyone. So maybe I have overlooked something. In the meantime, I resolved this with the following approach:

/*  Validate fields before submitting to the server. */
editor.on(`preSubmit`, function(e, data, action)
{
    /*
        Inline edit will not give access to all the editable
        fields, but only to the edited one. So we need to check
        which field has been edited before we can attempt to
        do any validation.
    */

    field = e.currentTarget.s.includeFields[0];
    fieldVal = eval(`this.field("`+field+`").val()`);

    switch (field)
    {
        case `field1`:
            if ( ! fieldVal)
            {
                field.error(`message1`);
            } 
            break;

        case `field2`:
            if ( ! fieldVal)
            {
                field.error(`message2`);
            }
            break;

        .........
        .........
    }

    if (this.inError())
    {
        return false;
    }
});

I would like to know, however, if there is not another way to achieve this, for example with an already existing API function.

Replies

  • Tester2017Tester2017 Posts: 145Questions: 23Answers: 17

    One correction in my example code.

    Where I am setting field errors it should be:

    this.field(`field1`).error(`message1`);
    this.field(`field2`).error(`message2`);
    
  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin

    displayed() should give you the field being edited.

    Allan

  • Tester2017Tester2017 Posts: 145Questions: 23Answers: 17

    OK, thanks. This is what I was looking for. But despite many search attempts, I was not able to find it.

This discussion has been closed.