Hide form field on Create
Hide form field on Create
mattw
Posts: 54Questions: 10Answers: 0
Hello, I have seen many questions/answers about showing/hiding form fields when a row is being edited. I would like to do this for when a Create occurs during initCreate however I can only seem to hide a field when an Edit occurs.
Should something like this work?
editor.on('initCreate', function() {
editor.show(); //Shows all fields
editor.hide('justification');
});
This does work on initEdit
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Yes, that should work, and it appears to do so if I use:
on this example. The Position field is hidden when the create form is shown.
Perhaps you could link to an example showing the issue please?
Thanks,
Allan
Thanks for your quick response. For some reason I still cannot get this to work. More odd is the fact that it does work if I do edit / initEdit.
Unfortunately my datatables website is used internally at my company so I do not have a good link for you. Perhaps if I just can't get it working I will use 2 editors.
Here is the defined field that I want to hide on create and how I am trying to hide it.
That looks like it should be perfect. Are you using the latest version of Editor (1.6.3)?
Allan
I am using 1.6.2, could that be the problem?
Its possible but I think unlikely since there is nothing about anything related to that in the release notes and I don't remember changing anything in that area for 1.6.3. But it would be worth updating to 1.6.3 just in case.
Is it possible to PM me a link so I can see it, or is it completely internal with no WAN access?
Thanks,
Allan
It is completely internal unfortunately and has a python backend so will be difficult to get everything to you. I'll give the code a good review and then post my findings here or mark question as answered either way.
It might be worth running
displayed()
in a few places to sanity check - e.g.:Allan
this is what my console shows when I do that (summarized):
[ ]length: 0__proto__: Array(0)
[ ]length: 0__proto__: Array(0)
That's odd. It suggests that not a single field is shown. Are you running
clear()
anywhere perhaps? That would remove all existing fields.Allan
No I'm not running clear( ). I thought that was odd as well considering all the fields are being shown. I'm going to go ahead and use 2 editors for now.
I wanted to add to this that if you create, and then close the create dialog and edit, the fields will still be hidden. You must also tap into the edit init and re-show all fields.