editor fields def not working
editor fields def not working
sid@nomisma.in
Posts: 11Questions: 2Answers: 0
in editor i'm not able to assign a default value using def option in editor during initialization. Looks straight forward to me but is there a gotcha? below is an example usage of mine
fields:[
{
label:"some label",
name:"some name",
def: "default value"
}
]
Everything else works perfectly fine. I was able to integrate well in to my node server.
Just this default value isnt getting populated.
This discussion has been closed.
Answers
From the docs:
Having got a reference to the field instance, you can then set values:
not working.
Is the field value
undefined
when editing?You code snippet should work. Might need to look at your code to determine the problem.
Kevin
nothing get populated. just blank.
below is the code , removed all extra fields.(for privacy reasons)
Everything works perfectly, even server side curd operations. Just this default value is being stubbon.
When you create a new row is the field populated with the default value?
According to
fields.def
the default will be set when the value isundefined
. My understanding is If the value isnull
or""
then the default won't be set.If the value is blank not
undefined
then you can use something like this to populate the blank filed with a "default" value:Kevin
In Created Mode it works like a charm.
But in edit mode, its a disaster.
"According to fields.def the default will be set when the value is undefined. My understanding is If the value is null or "" then the default won't be set."
In which world does this make sense?
I need a default value when something doesn't have value, it could be undefined, null or "". I think you need to change this behaviour asap
In edit mode the field should already have a value, and therefore the default isn't used.
An empty string is a perfectly valid value. The default will not override an empty string nor should. It should however take the place of undefined (I'll need to check what happens with null).
If you link to a test case showing the issue that would greatly help in our chances of being able to successfully help you resolve this (and if I can improve Editor along the way, so much the better!).
Allan
@ Assuming "" to be a valid value is a bit tricky.
Its not always a valid value. Many databases have columns with not null whose default is "" .
I think you need to check for "" also along with null case. Im sure its super tricky to resolve this.May be you're better off considering it as valid value.
Test cases i'd like to but i'm a bit occupied, ill do it over the weekend.
There is one more solid bug in editor.
So to get the default value i hacked my code a bit , used select and inserted what i want as default as first element of the array.that i think solved it but wait.. here is the catch
formOptions : {
main:{
submit:'changed',
}
},
Now when a default value is applied, it doesn't get sent to server cause form thinks its value has not been changed.
But the whole point of having default value is to save it, where as its not happening .
I had to remove submit :' changed' option.
Consider for example a "Description" field or "Extra notes" - an empty string is absolutely valid. What I think you are suggesting is that something like a telephone number might be stored as
null
rather than an empty string if there is no input. If so, that's why Editor's server-side libraries provideIfEmpty
formatters. Keep in mind also that you don't really want the end user to have to tick a "null" checkbox on the client-side - better to have an empty string stored either as null or an empty string as required by the schema.Could you give me a link showing the issue with the
submit: 'changed'
please?In general I would not expect the default to be used for a row being edited. It would only ever be useful if a new column / field has been added since the original data was added (and even then, it would need to have a default value in the database to have been added).
Allan