Concatenate and Write Cascading Dropdown Selections to Text Field

Forums Dynamic Forms for SharePoint Concatenate and Write Cascading Dropdown Selections to Text Field

This topic contains 4 replies, has 2 voices, and was last updated by  Mike 2 hours, 43 minutes ago.

  • Author
    Posts
  • #24308

    Mike
    Participant

    Alex,

    I’ve reviewed several posts but nothing does exactly what I’m looking for.

    Use case: Multi-value lookup to a second list. User selects Choice 1, and one or more Choices in the second text box. Once user selects these a script runs that concatenates Choice 1 with each of the choices in the second text box and writes these to a multi-line text box in the form. Output example: Choice 1-Choice 1a, Choice 1b, Choice 1c. This should appear in the form in front of the user so they see the captured selections.

    Then the Selected Options are cleared (and it would be nice if they did not re-appear in the Available Options boxes to avoid confusion) so that the user can select a second choice (Choice 2) from the first text box and one or more Choices from the second text box. The same concatenation then occurs in real time and results (e.g., Choice 2-Choice 2a, Choice 2b) are written to the same multi-line text box. A pipe symbol can serve as a delimiter between the sequence of choices.

    Example:
    Choice 1-Choice 1a, Choice 1b, Choice 1c | Choice 2-Choice 2a, Choice 2b

    We will then do a lookup to this multi-line text box from another list. This will enable aggregation of data in numerous combinations.

    Thanks for your help. Let me know if you need a diagram or more info.

    Mike

    • This topic was modified 5 days, 2 hours ago by  Mike. Reason: update title
  • #24313

    Alexander Bautz
    Keymaster

    I’m not sure exactly what you try to do here, but is seems a bit cumbersome. Are you using a sharepoint multilookup column, or the cascading dropdown with multi choice?: https://spjsblog.com/dffs/dffs-plugins/spjs-cascading-dropdowns/

    Unfortunately you cannot use a multiline textbox in a lookup column so I’m not sure your suggested solution will work.

    If you have some more detains I might be able to help.

    Alexander

  • #24325

    Mike
    Participant

    I’m using the DFFS cascading dropdown with multi-choice.

    I still need a solution (as described above) that copies the selected cascading dropdown options to a multi-line text box, deletes the selected options in the cascading boxes, then allows another set of available options to be selected and copied to the same multi-line text box.

    I’ll use a SPD workflow to copy the multi-line text box to another list.

    Thanks

    Mike

  • #24340

    Alexander Bautz
    Keymaster

    You can use something like this:

    function concatenateCasc(fin1,fin2,targetField){
    	var v1 = getFieldValue(fin1);
    	var v2Arr = getFieldValue(fin2).split(";\n");
    	// Remove the last blank item
    	v2Arr.pop();
    	var nVal = v1+"-"+v2Arr.join(", ");
    	// Set the value in the other field
    	var currValue = getFieldValue(targetField);	
    	setFieldValue(targetField,currValue !== "" ? currValue + "|" + nVal : nVal);
    	// Remove the current option in the first select
    	jQuery("#"+fin1+"_casc option:selected").remove();
    	// Clear the value in the casc-select by selecting the fiest option in the first dropdown
    	jQuery("#"+fin1+"_casc option:first").prop("selected",true).trigger("change");
    }
    
    // Call with the FieldInternalName of level 1 and 2 of the cascading dropdown and the internal name of the target to write the value to.
    concatenateCasc("Level1Single","Level2Multi","TargetField");

    I’m not sure how you want to trigger this writing of the values – from a button maybe?

    Alexander

  • #24355

    Mike
    Participant

    Yes, a button in the form could trigger writing each set of selected options chosen from the cascading dropdown available options. What would I need to call it?

    Mike

You must be logged in to reply to this topic.