Add Multiple rows with the same value

Add Multiple rows with the same value

schwaluckschwaluck Posts: 103Questions: 27Answers: 1

Hello everybody,

I am looking for a solution for the following requirement:

I want to be able to create several entries with the same values at once using the editor form. The user should be able to enter in a text field in the Editor Form how many identical entries should be created. Now I have already found the methods "rows.data()" and "row.data()", which I think are a good approach. But now I am thinking about how to implement this method in combination with the input regarding the number of rows to be inserted.
Have any of you already implemented something like this or any idea how to handle it?

I am happy about any suggestions! :)

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    This example from this thread should get you going. It's splitting the e-mail address and making duplicate entries based on that. You could use that as a starting point for your use-case,

    Colin

  • schwaluckschwaluck Posts: 103Questions: 27Answers: 1

    Hey Colin, thanks for the tip. I have looked at the code once and tried to apply it to my problem.

    Currently I used a custom editor form with an extra field to get the number of rows which should be created and that works fine.

    In my JS File I added the following code:

        var number;
        editor.on('preCreate', function(e,json,data,action) {
            number= parseInt(document.getElementById('number_entries').value, 10);
        });
        editor.on('postCreate', function(e,json,data,action) {
            if (number> 1) {
            editor
            .create(number,false)
    
            /*.set('Column_0', json.data[0]["Column_0"])
            .set('Column_1', json.data[0]["Column_1"])
            .set('Column_2', json.data[0]["Column_2"])
            .set('Column_3', json.data[0]["Column_3"])
            .set('Column_4', json.data[0]["Column_4"])
            .set('Column_5', json.data[0]["Column_5"])
            .set('Column_6', json.data[0]["Column_6"])
            .set('Column_7', json.data[0]["Column_7"])
            .set('Column_8', json.data[0]["Column_8"])
            .set('Column_9', json.data[0]["Column_9"])
            .set('Column_10', json.data[0]["Column_10"])
            .set('Column_11', json.data[0]["Column_11"])
            .set('Column_12', json.data[0]["Column_12"])
            .set('Column_13', json.data[0]["Column_13"])*/
    
            /*.set('Column_0', editor.field("Column_0").get())
            .set('Column_1', editor.field("Column_1").get())
            .set('Column_2', editor.field("Column_2").get())
            .set('Column_3', editor.field("Column_3").get())
            .set('Column_4', editor.field("Column_4").get())
            .set('Column_5', editor.field("Column_5").get())
            .set('Column_6', editor.field("Column_6").get())
            .set('Column_7', editor.field("Column_7").get())
            .set('Column_8', editor.field("Column_8").get())
            .set('Column_9', editor.field("Column_9").get())
            .set('Column_10', editor.field("Column_10").get())
            .set('Column_11', editor.field("Column_11").get())
            .set('Column_12', editor.field("Column_12").get())
            .set('Column_13', editor.field("Column_13").get())*/
    
            .set('Column_0', "1234")
            .set('Column_1', "1234")
            .set('Column_2', "1234")
            .set('Column_3', "1234")
            .set('Column_4', "1234")
            .set('Column_5', "1234")
            .set('Column_6', "1234")
            .set('Column_7', "1234")
            .set('Column_8', "1234")
            .set('Column_9', "1234")
            .set('Column_10', "1234")
            .set('Column_11', "1234")
            .set('Column_12', "1234")
            .set('Column_13', "1234")
            .submit();
            }
        });
    

    Note: In the annotated rows I tried to grab the data for the individual columns based on the input of the user.

    If I now enter e.g. the value 4 for the field "number_entries", an entry with the entered values is created, but the entries with the values "1234" are not created.

    However, at this point I do not know where my fault is.

    Can you help me here?

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    It needs to go into the submitComplete as in my example, as only one submission can be active at a time. Have you tried that?

    Colin

  • LapointeLapointe Posts: 430Questions: 81Answers: 4
    edited December 2020

    Hi
    precreate is called at editor create mode start, postcreate after create end.

    I think you want to create a loop

    for (vari=0; i<parseInt(document.getElementById('number_entries').value, 10); i++){
        editor.create(false).set('fieldname1','YourValue1').set('fieldname2','YourValue2');
    }
    

    you can do that on every event outside the editor postcreate event... perhaps document.getElementById('number_entries').onChange()

  • schwaluckschwaluck Posts: 103Questions: 27Answers: 1

    Hello Colin and Lapointe,

    first of all thanks for your response.
    @Colin I have tried that before but faced the isse that the event got also called after a deletion or an update.

    I have now adapted the code as follows based on your ideas:

        var number;
        editor.on('create', function(e,json,data,action) {
            number= parseInt(document.getElementById('number_entries').value, 10);
        });
        editor.on('submitComplete', function(e,json,data,action) {
            for (var i=0; i < number; i++){
                editor
                .create(false)
                .set('Column_1', "test32")
                .set('Column_2', "2020-12-02+12:31:26")
                .set('Column_3', "abcde")
                .set('Column_4', "abcde+fghi")
                .set('Column_5', "abcde")
                .set('Column_6', "342")
                .set('Column_7', "test32")
                .set('Column_8', "test32")
                .set('Column_9', "2020-12-02+12:31:26")
                .set('Column_10', "Open")
                .set('Column_11', "abcde")
                .set('Column_12', "test32")
                .set('Column_13', "34")
                .set('Column_14', "test32")
                .submit();
            }
        });
    

    However, it still does not work like it should. If I create a new entry via the form and enter e.g. the value 3 in the field "number_entries". The entry with the remaining data will be created, but the 3 entries, which should be created in the context of the submitComplete Event, will not be created. However, I do not receive any error messages which could help me in any way.

    Could it be due to the values I submit, e.g. "2020-12-02+12:31:26")?

  • LapointeLapointe Posts: 430Questions: 81Answers: 4

    Hi
    Just a question... are all these fields (column_??) part of editor fileds ?

  • schwaluckschwaluck Posts: 103Questions: 27Answers: 1

    Hi Lapointe,

    yes all the mentioned fields are also editor fields. :)

  • LapointeLapointe Posts: 430Questions: 81Answers: 4

    did you test .create(true) just to have a look on what the form display (try with number = 1)
    or just .open() before submit for same purpose
    I think your data is on database... do the field allow these setting (type, length, ...)

  • schwaluckschwaluck Posts: 103Questions: 27Answers: 1

    Hi Lapointe,

    i tried your proposal once and the editor form opens now, but the values are not entered automatically. I think this is the problem. Now the only question is why the values are not inserted. The names of the fields or columns are correct in any case. I checked that again.

    In any case, thanks for your help. Do you have an idea what the problem described above might be?

  • colincolin Posts: 15,146Questions: 1Answers: 2,586
    Answer ✓

    It would be worthwhile updating my example so we can see it occurring, if you're unable to link to your page,

    Colin

This discussion has been closed.