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
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
One correction in my example code.
Where I am setting field errors it should be:
displayed()
should give you the field being edited.Allan
OK, thanks. This is what I was looking for. But despite many search attempts, I was not able to find it.