Web AppBuilder Widget Configuration Validation

3504
5
Jump to solution
11-14-2015 12:53 PM
JamilNawaz
New Contributor II

I have created a custom widget with configuration in web appbuilder. What I need to do is disable "Ok" button or do nothing if all fields in the config screen are not filled. In other words, I need to do save only when all inputs are filled. Any idea how to achieve it?

Regards,

Jamil

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Jamil,

   OK Sorry, they do not provide access to disable the main widget settings button like that. You can use the code I provided for an subsequent/additional popups.

View solution in original post

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

Jamil,

  Simple as

this.popup.disableButton(0);

JamilNawaz
New Contributor II

Where to write that? I write on Settings.js postCreate method, but there is no "this.popup".

0 Kudos
JamilNawaz
New Contributor II

I am doing like this

return declare([BaseWidget], {

            baseClass: 'jimu-widget-MyWidget-setting',

            postCreate: function () {

                this.inherited(arguments);

                this.popup.disableButton(0);

            },

});

Regards,

Jamil

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jamil,

   OK Sorry, they do not provide access to disable the main widget settings button like that. You can use the code I provided for an subsequent/additional popups.

0 Kudos
MarkBuie1
New Contributor III

I'll provide my solution, even though this is an old post, since it's a top Google result.

 

As far as I know, you cannot disable the OK button, but there is a way to prevent users from moving forward if they don't meet your validation test.

 

When you click OK on the widget settings page, the getConfig() method is fired. If we return false on this method, the user will not be able to close the settings page. Therefore, we can add a validation method and return false if some criteria is not met - with a popup indicating what the user omitted.

 

getConfig: function() {   
  if ( !this.yourValidationMethod ) {      
    return false   
  } 
},  

yourValidationMethod: function() {  
  if (lang.trim(this.someInput.get('value')) === '') {     
    return false;   
  } else {      
    return true    
  } 
}
0 Kudos