Results 1 to 3 of 3

Thread: If particular tagfield item selected, also select an item in another tagfield

  1. #1
    Sencha User
    Join Date
    Mar 2016
    Posts
    8
    Answers
    2

    Default Answered: If particular tagfield item selected, also select an item in another tagfield

    I have two tagfields on my form, "status" and "orgAssignmentStatus". Each has choices like "Open", "On Hold", "Completed". If the user selects "Completed" in "status", I want to automatically select "Completed" for "orgAssignmentStatus" (if already selected, leave it selected).
    I added a listener for the "select" event on the "status" tagfield, and the following code correctly sets the Boolean "rsCompleted" to true if "Completed" is checked. So now, I need to know how to find the correct item under "orgAssignmentStatus", and make sure it's selected. Pointers?
    I'm really new to both ExtJS and SA3.
    Code:
        onStatusSelect: function(combo, record, eOpts) {
            console.log("testing: onStatusSelect!!");
            console.log("record.length=" + record.length);
            console.log(record);
            var rsCompleted = false;
            for (var i = 0, count = record.length; i < count; i++) {
                console.log("i:"+1);
                console.log(record[i].data.description);
                if (record[i].data.description === 'Completed') rsCompleted = true;
            }
            console.log("rsCompleted (flag set)=" + rsCompleted);
            if (rsCompleted) {
                console.log("update orgAssignmentStatus");
            }
        },

  2. I got it. The needed method was "addValue", which (as desired) adds the value if it's not already there, but does not add extras if it _is_ already there. (I initially tried "select", but that replaced any pre-selected values with just the new one. The "addValue" method preserves the pre-selected values. The final code, with debug logs commented-out:
    Code:
        onStatusSelect: function(combo, record, eOpts) {
            //console.log("record.length=" + record.length + ", record:");
            //console.log(record);
            // MW: check to see if Request Status contains "Completed"
            var rsCompleted = false;
            for (var i = 0,
                count = record.length; i < count; i++) {
                //console.log("i:"+1);
                //console.log(record[i].data.description);
                if (record[i].data.description === 'Completed')  {
                    rsCompleted = true;
                }
                
            }
            //console.log("...rsCompleted (flag set)=" + rsCompleted);
            if (rsCompleted) {
                // If Request Status contains "Completed",
                // make sure Org Assignment Status does also
                var OrgAssignmentStatusTagfield = this.lookupReference('orgAssignmentStatus');
                OrgAssignmentStatusTagfield.addValue('Completed');
            }
        },

  3. #2
    Sencha User
    Join Date
    Mar 2016
    Posts
    8
    Answers
    2

    Default

    I got it. The needed method was "addValue", which (as desired) adds the value if it's not already there, but does not add extras if it _is_ already there. (I initially tried "select", but that replaced any pre-selected values with just the new one. The "addValue" method preserves the pre-selected values. The final code, with debug logs commented-out:
    Code:
        onStatusSelect: function(combo, record, eOpts) {
            //console.log("record.length=" + record.length + ", record:");
            //console.log(record);
            // MW: check to see if Request Status contains "Completed"
            var rsCompleted = false;
            for (var i = 0,
                count = record.length; i < count; i++) {
                //console.log("i:"+1);
                //console.log(record[i].data.description);
                if (record[i].data.description === 'Completed')  {
                    rsCompleted = true;
                }
                
            }
            //console.log("...rsCompleted (flag set)=" + rsCompleted);
            if (rsCompleted) {
                // If Request Status contains "Completed",
                // make sure Org Assignment Status does also
                var OrgAssignmentStatusTagfield = this.lookupReference('orgAssignmentStatus');
                OrgAssignmentStatusTagfield.addValue('Completed');
            }
        },

  4. #3
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985
    Answers
    506

    Default

    Glad to hear that you got it working, and thanks for sharing your solution with the community.

Similar Threads

  1. ToolTip for the selected tagfield items
    By lalit007 in forum Ext JS 6.x Q&A
    Replies: 3
    Last Post: 22 Mar 2016, 5:24 AM
  2. [FIXED] TagField single select setValue is broken (since 6.0.1)
    By A. Llorente in forum Ext JS 6.x Bugs
    Replies: 0
    Last Post: 14 Oct 2015, 2:57 AM
  3. Tagfield: edit record value with tagfield
    By josei in forum Ext 5: Q&A
    Replies: 4
    Last Post: 8 May 2015, 5:40 AM
  4. [FIXED] tagfield backspace/delete erase all selected items bug
    By oceany in forum Ext 5: Bugs
    Replies: 1
    Last Post: 2 Dec 2014, 7:20 PM
  5. Replies: 2
    Last Post: 1 Oct 2014, 3:10 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •