Hide form field on Create

Hide form field on Create

mattwmattw 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

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    edited July 2017 Answer ✓

    Yes, that should work, and it appears to do so if I use:

    editor.on('initCreate', function() {
            editor.show(); //Shows all fields
            editor.hide('position');
        });
    

    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

  • mattwmattw Posts: 54Questions: 10Answers: 0

    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.

    fields: [ 
                    {label:"Change comments",
                    name:"justification",
               }
    ]
    
    editor.on('initCreate', function() {
            editor.show(); //Shows all fields
            editor.hide('justification');
        });
    
  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    That looks like it should be perfect. Are you using the latest version of Editor (1.6.3)?

    Allan

  • mattwmattw Posts: 54Questions: 10Answers: 0

    I am using 1.6.2, could that be the problem?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    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

  • mattwmattw Posts: 54Questions: 10Answers: 0

    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.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    It might be worth running displayed() in a few places to sanity check - e.g.:


    editor.on('initCreate', function() { editor.show(); //Shows all fields console.log( editor.displayed() ); editor.hide('justification'); console.log( editor.displayed() ); });

    Allan

  • mattwmattw Posts: 54Questions: 10Answers: 0

    this is what my console shows when I do that (summarized):

    [ ]length: 0__proto__: Array(0)
    [ ]length: 0__proto__: Array(0)

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    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

  • mattwmattw Posts: 54Questions: 10Answers: 0

    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.

  • washuit-iammwashuit-iamm Posts: 84Questions: 32Answers: 1

    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.

This discussion has been closed.