Consolidating messages against one editor

  • 1
  • Question
  • Updated 3 years ago
  • Answered
Hi All,

Have a page that contains numerous models, and a range of components linked to these models spread down the page. Components for a specific model are dispersed through the page, not all grouped together.

Problem is, on a save error I get standard messages replicated up the page against each of the multiple components linked to the affected model. Looks horrific.  Thus, Im trying to intercept all errors and aggregate them against one component at top of page.

in my save snippet, I am trying to push each error to target UI component using initiatorId param but getting nowhere.  Any suggestions on how this is used?  Relevant sections of my code below:

var myPage = skuid.$('#FormTitle');
var myeditor = myPage.data('object').editor;
.
.
.
models.save({ callback : checkResult }); // assume I save the models
function checkResult(result){
if(!result.totalsuccess) {
    myeditor.handleMessages(result.messages,{  initiatorId : "FormTitle" } );
   return false;
}
}
Photo of Carl

Carl

  • 120 Points 100 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
If you can't figure out the solution you are pursuing, you could instead create separate models for each component. It isn't the cleanest or most convenient option, but it may save you a few hours of trying to figure out how to do what you are trying to do.
Photo of Carl

Carl

  • 120 Points 100 badge 2x thumb
Thanks Raymond. I appreciate your response. Unfortunately with 11 models already that'd expand DML queries out to say 30 for the page, affecting efficiency and performance significantly. There must be a simple way to define where to put error messages surely ?
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
On certain components (like field editors) in the component settings there is a "Display" tab. On the display tab, there is an errors tab. It allows you to determine if errors are shown inline and whether you only want them to show upon hover.
Photo of Carl

Carl

  • 120 Points 100 badge 2x thumb
Yep good suggestion. I did try that and so now errors appear on fields AND against all elements in the page that is bound to the model that has validation errors - nasty UI experience!  I keep hoping that there is a way to consolidate all errors from all models onto one page element. Seems page hacks are the next step which seems counter productive.
Photo of Hasantha Liyanage

Hasantha Liyanage

  • 1,446 Points 1k badge 2x thumb
This works Carl :)

var params = arguments[0],    $ = skuid.$;
// Clear our list of messages
var myPage = skuid.$('#FormTitle');
var stepEditor = myPage.data('object').editor;
stepEditor.clearMessages();
var models = [
    skuid.model.getModel("DetailsForm"),
    skuid.model.getModel("SForm"),
    skuid.model.getModel("Qualificaiton")
];
var messages = [];
$.each(models,function(i,model){
   $.each(model.registeredLists,function(j,list){
       var listMessages = list.validateRequiredFields();
       if(listMessages && listMessages.length) {
           $.each(listMessages,function(){
              messages.push(this); 
           });
       }
   });
});

var DetailsModel = skuid.model.getModel('DetailsForm');
var DetailsForm = DetailsModel.getFirstRow();
if(DetailsForm.CountryOfBirth__c == 'Australia' && (DetailsForm.StateOfBirth__c ==='' || DetailsForm.CityOfBirth__c==='' )){
    messages.push({
        message: 'When Country of birth is Australia, State/Territory of birth and Suburb/City of birth are required',
        severity: 'ERROR'
    }); 
}
// If we have warning messages, do NOT proceed
if (messages.length) {
    // Have our step's editor handle the messages
    stepEditor.handleMessages(messages);
    return false;
}
(Edited)
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Thanks for sharing Hassantha...