Gordon Seidoh Worley
Gordon Seidoh Worley

Reputation: 8068

Validate ExtJS CheckboxGroup checked boxes

Using ExtJS 4, I have a Ext.form.CheckboxGroup and I want to do validation on this checkbox group like 'valid only when 1, 2, or 3 checkboxes checked' out of a set of maybe 10 checkboxes. There is an existing allowBlank: false config option I can set to ensure the CheckboxGroup has at least one checkbox checked. I'd like to get essentially the same functionality but with a custom validator function so that I can specify my own criteria.

How can I accomplish this?

Looking at the docs and code, I don't see a clear way to do this. Any suggestions?

Upvotes: 2

Views: 3257

Answers (2)

U and me
U and me

Reputation: 740

I recommend using one more attribute in config object to specify how many checkboxes or array of ids of checkboxes need checking. If you want the validation is just like a trigger (enable/disable), you can handle it in the change event handler.

In case you want to use validation with error message and/or make the component reusable, it is better to follow sha's way above.

Upvotes: 1

sha
sha

Reputation: 17850

You can try to extend standard Ext.form.CheckboxGroup by overwriting validate() method to return true when some number of checkboxes are checked.

I don't see anything more standard, but it should not be complicated.

Upvotes: 0

Related Questions