Nested editing default value

Nested editing default value

marianidiegomarianidiego Posts: 50Questions: 15Answers: 1

Link to test case:
https://editor.datatables.net/examples/datatables/nested.html

Description of problem:
What happens when nothing is selected? Or better, if the user deselect all?
Being able to define a default value for this case would be very practical.

Replies

  • rf1234rf1234 Posts: 2,955Questions: 87Answers: 416
    edited August 16

    If nothing is selected you can only have an editor "create" event. Is this what you want to refer to?

    Setting a default value for this is fairly easy. Just use "initCreate" or "open" with action "create".

    Something like this:

    siteEditor 
        .on('open', function (e, mode, action) {
            if ( action === "create" ) {
               this.set({ 'name': 'Koh Phangan',
                           'continent': 'Asia' });
            }
        })
    

    You can also address the embedded data table and attach event handlers. This would be the embedded data table which behaves like any other data table

    editor.field("users.site").dt():
    

    It's all in the docs ... please read. I haven't written data tables either: All I can do is check the docs ...

  • allanallan Posts: 63,290Questions: 1Answers: 10,428 Site admin

    Just to add to rf1234's post:

    What happens when nothing is selected? Or better, if the user deselect all?

    An empty value is submitted for the datatable field. It has no value, so an empty value is sent. The server-side can be configured to reject that if a value should be submitted.

    Being able to define a default value for this case would be very practical.

    Use field.def to define what should be selected as the default value at initialisation time, or use the field().def() value after initialisation.

    Another option would be to have the server, instead of doing validation and rejecting the empty value, have it write a default value instead of empty if an empty value is submitted. I think that might be confusing to the user, but it is an option.

    Allan

  • rf1234rf1234 Posts: 2,955Questions: 87Answers: 416

    Thanks, Allan. I must admit that I had forgotten about all the other options. This forum is really helpful when it comes to discovering all of Editor's and Data Tables' rich capabilities! Thanks for providing such a brilliant solution, Allan. Without your solution my little cloud company wouldn't exist: No way for me to code all of the the stuff I need just by myself!

    Roland

  • allanallan Posts: 63,290Questions: 1Answers: 10,428 Site admin

    That's really kind of you to say - thank you. I'm delighted that DataTables and Editor can help in some small way :)

    Allan

  • rf1234rf1234 Posts: 2,955Questions: 87Answers: 416

    I'm delighted that DataTables and Editor can help in some small way

    British understatement, I guess. But I like it :smiley:

    One of the features that make such a big difference for my clients is that you can show / hide / prefill fields depending on the context. I use "dependent" over 300 times in my current solution. I also use it to load context-specific options for "select" fields. This makes life a lot easier for my clients because they only see relevant fields and not "everything": They can enter all details of a loan on one single screen for example, whereas competing solutions require opening three screens to do the same thing.

  • allanallan Posts: 63,290Questions: 1Answers: 10,428 Site admin

    I knew you used dependent() a fair amount, but hadn't clicked it was quick as much as that! It was a method that came about from a chat with another dev who was using Editor - I almost suggested that he just use event listeners, but I sure am glad I brought it into the library. Amazing how little things can add up :-)

    Currently planning Editor 2.4 changes - hopefully there will be a few things to smile about there as well :).

    Allan

Sign In or Register to comment.