Leeyung
Leeyung

Reputation: 131

Apostrophe input field validation

I want to add a validation to an Apostrohe input field. Suppose I have an input field of type string and i want apostrophe to throw an error if the user had entered some specific text(say hi)

Kindly help

Upvotes: 0

Views: 290

Answers (1)

Stuart Romanek
Stuart Romanek

Reputation: 2157

In Apostrophe you can create your own field types, which is useful for these kind of project-specific requirements. These custom field types can have their own validation and sanitization methods and requirements.

The documentation outlines what is needed to write your own field here https://docs.apostrophecms.org/apostrophe/tutorials/intermediate/custom-schema-field-types

Since you're not creating a new UI (you're borrowing from the existing string field type) I would use the string field type as a guide in the source. https://github.com/apostrophecms/apostrophe/blob/master/lib/modules/apostrophe-schemas/index.js#L1089

Use the errors it throws for min and max as your guide for throwing errors.

If you have specific issues down the road please follow up!

Upvotes: 0

Related Questions