Editor: Bulk row creation based on single Editor form?

Editor: Bulk row creation based on single Editor form?

pharrispharris Posts: 7Questions: 2Answers: 0

I have an Editor form with 14 fields. The first field is called Barge.

My users would like to do bulk row entry where they can select multiple Barges and enter the data for the remaining 13 fields. Once they hit submit, a new row would be created for each barge in the array with the remaining 13 fields the same for each barge row.

I created a custom field plug-in that allows the multi-selection for the barges and returns an array.

I am looking into using the create() api function and passing in the length of the array as the count option, but I'm getting hung up on where/when I should call create(). At first, I tried to catch the preSubmit and create the additional rows, but that wasn't working out very nicely.

Please assist! Thank you.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,812Questions: 1Answers: 10,516 Site admin
    Answer ✓

    Hi,

    Editor's create() method does have the option of creating multiple rows by passing it a count parameter, however, the GUI doesn't lend itself to entering different data for fields - the current GUI would work for 13 of your fields, but not at all for the first one.

    Perhaps the way to do this would be to present the standard Editor create form, but remove the Submit button with your own custom button (buttons()) which will get the values entered by the user, and then use the API to call create() and use multiSet() to enter the row information as required from the stored user input. Then when you submit that it will work well with the Editor PHP / .NET libraries.

    Allan

  • pharrispharris Posts: 7Questions: 2Answers: 0

    Is it possible to use the multiSet function in a loop? The number of rows to be created will be dynamic.

  • pharrispharris Posts: 7Questions: 2Answers: 0

    I did manage to get everything to work in a loop, but I've found that when I call editor.create(bargeList.length, false) then set the values with multiSet, it loses the previous editor instance's values. Any idea for a work around? Should I just store them all prior then assign them out?

    Thanks

  • allanallan Posts: 63,812Questions: 1Answers: 10,516 Site admin
    Answer ✓

    it loses the previous editor instance's values.

    Yes - each Editor instance can only be in one state at a time. That's why I suggested getting the values from the Editor before then calling create(). Just var vals = editor.vals(); should do it.

    Allan

  • pharrispharris Posts: 7Questions: 2Answers: 0

    Allan,

    My solution has been working great, but I ran into an error while testing cross-browser. I have the following:

    var field = editor.field("OWNER");
    field.multiSet(0, "CBC");

    I get an error only in IE11 that says cannot set push of null reference.

  • allanallan Posts: 63,812Questions: 1Answers: 10,516 Site admin

    Can you give me a link to the page showing the issue so I can debug it please? I've just tried multiSet in IE11 and it appears to work as expected in my example.

    Allan

  • pharrispharris Posts: 7Questions: 2Answers: 0

    Allan,

    I think I figured out what is happening, but I don't understand how to fix it just yet. I have a situation in which I'd like a field to be a different type in create vs edit modes. I read on another post that there is no current way to change the type dynamically, so you just clear() then add() the field.

    The field in question is the OWNER field. In my create mode, I would like it to be a custom type called "multiselect", and in edit I would like it to be "select2". I put the clear() and add() calls in initEdit and initCreate events. However, in my submit override that you suggested above, I call "this.create(bargeList.length, false);" and it thinks that the OWNER field does not exist and that is the null reference. If I remove the clear()/add() calls and set it to just a single type, everything works perfectly fine.

    I'm not sure if I can provide a test site, as this is all hosted in our intranet. I'll see about getting an outside facing dev environment, but it's not likely.

    Additionally, this isn't specific to IE11, I just happened to break it right before going to cross browser test. Oops!

This discussion has been closed.