enable Button snippet on visible required fields having values

  • 2
  • Article
  • Updated 3 years ago
Inspiration for this idea came from Moshe's clone snippet. :D

Snippet to evaluate required fields.

skuid.snippet.register('modelReqsMet',function(args) {var params = arguments[0],
	models = arguments[1],
	$ = skuid.$,
	regFields,
	enableButton = true;

    // loop through models
    $.each(models,function(m, model){
        regFields = model.registeredFields;
        $.each(regFields,function(f,field){
            if (field.required && !field.row[field.id]) {
                enableButton = false;
            }
        });
    });
    
    return enableButton;
});

Sample snippet to check one model and set a UI only field of enableNext boolean to true. enableNext = true is used as an Enable Condition on a wizard button in my use case.
skuid.snippet.register('nuAgentReqs',function(args) {var params = arguments[0],
    $ = skuid.$,
    modelToUpdate = skuid.$M('nuAgency'),
    modelToUpdateRow = modelToUpdate.getFirstRow(),
    modelsToCheck = [skuid.$M('nuAgent')],
    snip = skuid.snippet.getSnippet('modelReqsMet');
    

    if (snip(arguments[0], modelsToCheck)){
        modelToUpdate.updateRow(modelToUpdateRow,{enableNext: true});
    }
});
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,674 Points 20k badge 2x thumb

Posted 3 years ago

  • 2
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Thanks for sharing these Pat.  They are very nice!