Thoughts on extending foam.String for custom validation

4 views
Skip to first unread message

Joel Hughes

unread,
Nov 10, 2017, 12:15:58 PM11/10/17
to foam-framework-discuss
We are adding validation on fields containing email or phone numbers, for example, via validateObj.  
Obviously we'd like to do this only once. 

Initial thoughts were to 'extend' foam.String with a class such as 'PhoneNumber' with an appropriate validateObj.
This isn't working, validateObj is not entered.

It's been too long since I've fiddled at this level of FOAM, so some ideas/help would be appreciated. 

Thanks
Joel 


Kevin Greer

unread,
Nov 10, 2017, 12:25:54 PM11/10/17
to Joel Hughes, foam-framework-discuss
We already have extended String types defined in types.js, like 'PhoneNumber', 'Password', 'Email', etc.

You can set the assertValue Property Property to add validation rules for a Property. It is called when a property is set, after adapt but before preSet.

--
You received this message because you are subscribed to the Google Groups "foam-framework-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to foam-framework-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joel Hughes

unread,
Nov 10, 2017, 12:47:33 PM11/10/17
to foam-framework-discuss
Perfect. Thank you.

Joel Hughes

unread,
Nov 10, 2017, 12:56:12 PM11/10/17
to foam-framework-discuss
When 'in' assertValue, how would one know what property they are?  To determine the property's name or label, for example?
Thanks
Joel 

Kevin Greer

unread,
Nov 10, 2017, 1:22:22 PM11/10/17
to Joel Hughes, foam-framework-discuss
assertValue: function(newValue, property) { // this == the object }

So property.name is the property name. 'this' is the object that contains the property. The new/proposed value is passed in as the first argument to the assertValue function.

To unsubscribe from this group and stop receiving emails from it, send an email to foam-framework-discuss+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages