Retrieve checkbox values saved with ipOpts

Retrieve checkbox values saved with ipOpts

GargiucnGargiucn Posts: 104Questions: 29Answers: 0

Good morning, I am creating a survey and use:

if (drt_tipo == "input"){   
    domEditor.clear("isorapptestdom.drt_ris1");
    domEditor.add( {
        label: "Risposta",
        name: "isorapptestdom.drt_ris1"
    } );
}       
if (drt_tipo == "radio"){
    domEditor.clear("isorapptestdom.drt_ris1");
    domEditor.add( {
        label: "Scelte",
        name: "isorapptestdom.drt_ris1",
        type:  "radio",
        options: ["A", "B", "C"]
    } );
}
if (drt_tipo == "checkbox"){
    domEditor.clear("isorapptestdom.drt_ris1");
    domEditor.add( {
        label: "Scelte",
        name: "isorapptestdom.drt_ris1",
        type:  "checkbox",
        separator: "|",
        unselectedValue: "A",
        ipOpts: [ "A", "B", "C" ]
    } );
}

to create the questions in the various formats and always using the same text field for the answers.
The "checkbox" field creates the list of answers separated by "|".
I would like to understand how to do in edit mode to retrieve selected answers and display them correctly in editor mask.
Is the last problem I have left to finish the project...
Thanks for the help...

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Hi,

    I don't quite understand what you are looking for I'm afraid. On edit, the isorapptestdom.drt_ris1 property will contain something like A|C does it not? So the A and C checkboxes should be checked.

    Allan

  • GargiucnGargiucn Posts: 104Questions: 29Answers: 0

    Unfortunately, in edit no value is selected...

  • GargiucnGargiucn Posts: 104Questions: 29Answers: 0

    In the initial example, I simplified things a bit.
    I actually populate the checkbox based on the value of another variable:

    if (drt_tipo == "checkbox"){
        //let rispSplit = domEditor.val("isorapptestdom.drt_ris1").split("|");
        //let num_rispSplit = rispSplit.length;
        //alert(num_rispSplit);
        domEditor.clear("isorapptestdom.drt_ris1");
        domEditor.add( {
            label: "Scelte",
            name: "isorapptestdom.drt_ris1",
            type:  "checkbox",
            separator: "|",
            //unselectedValue: dom1,
            ipOpts: [ "" ]
        } );
        if (num_scelte_piene == 1){
            domEditor.field('isorapptestdom.drt_ris1').update( [
                dom1
            ] );
        }
        if (num_scelte_piene == 2){
            domEditor.field('isorapptestdom.drt_ris1').update( [
                dom1, dom2
            ] );
        }   
        if (num_scelte_piene == 3){
            domEditor.field('isorapptestdom.drt_ris1').update( [
                dom1, dom2, dom3
            ] );
        }   
    

    Could this be creating the problem?
    Basically I do a check to see which checkbox boxes are not empty.
    Surely there is a more elegant way to do this right?...

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    If you are able to give me a link to a page showing this issue, that would really help. For example, I'm not sure at what point this code is being executed? Also what is dom1, dom2 and dom3? Is it possible the data is numeric and those are strings?

    Allan

  • GargiucnGargiucn Posts: 104Questions: 29Answers: 0

    I checked. The problem occurs if I use field.update.
    It also occurs in this simplified example:

    if (drt_tipo == "checkbox"){
        domEditor.clear("isorapptestdom.drt_ris1");
        domEditor.add( {
            label: "Scelte",
            name: "isorapptestdom.drt_ris1",
            type:  "checkbox",
            separator: "|",
            //unselectedValue: dom1,
            ipOpts: [ "" ]
        } );
        domEditor.field('isorapptestdom.drt_ris1').update( [
            "A", "B", "C"
        ] );
    }
    

    I used "if" conditions:

     if (num_scelte_piene == 1){
            domEditor.field('isorapptestdom.drt_ris1').update( [
                dom1
            ] );
        }
        if (num_scelte_piene == 2){
            domEditor.field('isorapptestdom.drt_ris1').update( [
                dom1, dom2
            ] );
        }  
        if (num_scelte_piene == 3){
            domEditor.field('isorapptestdom.drt_ris1').update( [
                dom1, dom2, dom3
            ] );
        }  
    

    to exclude empty queries since I use 10 table fields for descriptions that I enter in the variables dom1, dom2, etc...

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    Is there any chance of a link to the page please? I'm still not clear when you are calling this code - is it in an initEdit event for example? If so, using clear() and then add() will not retain the current value.

    I think I'd need to see this happening to be able to diagnose and help resolve this.

    Regards,
    Allan

Sign In or Register to comment.