Default value not showing in editor text field
Default value not showing in editor text field
angekouf
Posts: 14Questions: 4Answers: 0
I have initialized an editor text field with
type:'text',
attr:{
type:'number',
min:0
},
def:'0'
Everything is working except the** default value** of the field (The text field remains empty at new)
I even tried extending the text field and setting val with jquery but still the same.
_fieldTypes.number = $.extend(true, {}, _fieldTypes.text, {
create: function (conf) {
conf.attr = conf.attr || {};
conf.attr.type = conf.attr.type || "number"
// Call original create
conf._input = $(_fieldTypes.text.create.call(this, conf));
return conf._input;
},
set: function (conf, val) {
return $(conf._input).val(val)
},
});
From the debugger I noticed that during set the val parameter is correct (0) but when setting the input val with jquery nothing happens when $(conf._input).val(val).
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I tested your code snippet in my project and it works:
You may want to provide a test case showing the issue:
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
I found the bug. If it is working properly for you then the bug appears only on my version of editor that allan provided for fixing this bug.
I had noticed for a while that for each element set function is called twice but it was working so I assumed it was normal. (You can see this both from the cosnole that outputs some debug info and by using breakpoints). The second time it is called the val parameter is undefined and it overwrote the previous value.
I created this extension:
and it works properly. If you want to avoid setting type 2 times you can do this for number specifically:
I have uploaded the file for testing here http://tests.southcrete.gr/office/accommodation
If you click new you will see 'Minimum rental days' is a number field wich has 0 as default. If you use a breakpoint on set method you will see that set is called twice for each element and the second time it is undefined. This overwrites the default value set for the text field.
This happens to all text fields since it occured even before I used html5 field type:number when it was just a text box. I think it may happen to all fields since according to the console it calls set with undefined for every field not just text fields.
Allan for now the debug info in the console are helpful. How can I later disable printing them when in production?
FYI I used Editor 1.6.0 for this test.
Kevin
I see.
I do not know if version 1.6.1 has this bug or not.
The fix allan gave me was for a bug in version 1.6.1, so the version I am running is an altered version of 1.6.1 (let's call it 1.6.1.1 or something like that )
So maybe the bug appears at the altered file not the original 1.6.1 version.
The trial of the 1.6.1 file has expired so I can not load it to verify.
Let's see what allan has to say when he has the time to look into it.
I was being lazy and not upgrading. Just updated Editor to 1.6.1 and still get the default value. Not sure if it makes a difference but I'm using the Bootstrap 3 integration scripts also.
Kevin
It does actually look like it might be related to the other fix. There are two
set
actions happening on the field, which is a problem because the second one isundefined
which is overwriting the default value.I'm not entirely clear on why this is happening yet. Let me dig into it a bit more and I'll gt back to you.
Allan
I'm as certain as I can be that this was a bug in the dev version only. @angekouf - I've just set you a PM with the update.
Regards,
Allan
It's working. Thanks allan
Thanks for the confirmation!
Allan