Can I set my Multi Picklist to not allow a user to "UnCheck All"

  • 1
  • Question
  • Updated 3 years ago
I have Multi-Pick list that when its values are checked it will Activate a condition in another model based upon what was selected.  This works great except when the user clicks "UnCheck All" and the condition appears to get set to "None" and thus my models return no data.  Additionally, I would also like to be able to default the Multi Picklist to be "All Values" rather than only one.
Photo of Jeff McBride

Jeff McBride

  • 160 Points 100 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Jeff...

How about just deactivating your condition if the value is empty?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Jeff,

Yes, you'll need some javascript.
How are you setting the values for the condition in the first place?

Assuming you're using the action framework, it will probably be as simple as a "nullCheck" script like this:

var model = skuid.$M('MyModel'),
row = model.getFirstRow(),
returnVal = false;
if (model.getFieldValue(row,'My_Field__c')) {returnVal = true'}
return returnVal;

The action framework sequence will only continue if the snippet returns true. If it returns false, it will perform any "error actions" that you set up. (such as "deactivate" and "query")
Photo of Jeff McBride

Jeff McBride

  • 160 Points 100 badge 2x thumb
I have a Model UI_OnlyForFilters  It has a UI Only Field called MARKET__UI I have an action on this model that fires when MARKET_UI is updated to set a condition on another model called PastDueOpp to the value(s) selected in the MARKET__UI field.  (MARKET__UI is a multi-picklist field with a set of specific values).  After I set the value and activate the condition on PastDueOpp, I have a subsequent action that re-queries the PastDueOpp model.  The crux of my problem now is that if the user "UnChecks All" on the MARKET__UI field, my PastDueOpp model returns no rows because (I think) the Condition is still active and is filtering where its market__c field is null.  Since it is a required field.... it returns no rows....  My desired state would be either to not allow the user to uncheck all or to deactivate the condition if they do.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Right.

So, make the first action of your action sequence that runs when MARKET_UI is updated "Run a skuid javascript snippet"

Here's your snippet:

var model = arguments[0].model,
row = arguments[0].row,
returnVal = false;
if (model.getFieldValue(row,'MARKET__UI')) {returnVal = true'}
return returnVal;
Then, add these two actions in the "error sequence" of that snippet in the action framework:
  • deactivate model condition
  • query model

Your full action framework should look something like this:


1. Run snippet
---- ! 1. Deactivate Condition
---- ! 2. Query Model
2. Activate and Set Value
3. Query Model
Photo of Jeff McBride

Jeff McBride

  • 160 Points 100 badge 2x thumb
Got to Work!  I had to use this syntax though....

var model = skuid.$M('UI_ONLY_ForFilters'),
row = model.getFirstRow(),
returnVal = false;
if (model.getFieldValue(row,'MARKET__UI')) {returnVal = true}
return returnVal;

Thank you!
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Glad you got it working!