I'm new to Carbon Fields. I'm writing about an issue that has bothered me to no end and even caused me to ditch Carbon Fields in favor of Piklist for a while. Piklist has support for custom validation and error messages, but it does not support repeatable fields with a length of zero. Because I need repeatable fields with a length of zero, I am back to Carbon Fields.
That being said, I still need custom validation and error messages. I understand that all validation is done with JavaScript. That does not stop me. I am even more versed in JavaScript than I am in PHP. I also understand that the data binding in JavaScript is done through Backbone, a model-view-controller framework similar to AngularJS. My question is: How do I get to a Backbone model that stores not only field values, but error messages and error states as well?
Hi @ssimo3lsuhsc ,
Can you share more details about what kind of validation you need:
Either a new custom field type that extends an existing one OR allowing any field type to have custom validation would make it work. The validation would return the error message to display, or else the Boolean value “true.” You can specify whether the validation should be done in Javascript or PHP as long as it is documented how to access other Carbon Fields post meta within the function.
Stuart Simon
Graphics Specialist
LSU Human Development Center
411 S Prieur St
New Orleans, LA 70112
http://www.hdc.lsuhsc.edu/
From: Atanas Angelov [mailto:[email protected]]
Sent: Monday, January 30, 2017 1:25 AM
To: htmlburger/carbon-fields carbon-fields@noreply.github.com
Cc: Simon, Stuart A. ssimo3@XXXXXXX.XXX; Mention mention@noreply.github.com
Subject: Re: [htmlburger/carbon-fields] Custom validation/Getting the Backbone model (#199)
EXTERNAL EMAIL: EVALUATE
Hi @ssimo3lsuhschttps://github.com/ssimo3lsuhsc ,
Can you share more details about what kind of validation you need:
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/htmlburger/carbon-fields/issues/199#issuecomment-275995028, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATRYOLVOJ0iFjY21Pv10E08b7p_DLr8tks5rXZBcgaJpZM4Lw5JA.
Hi @ssimo3lsuhsc ,
If you need to create a custom field with custom validation, you can check the next 2 resources:
However, please note that there is under development a full JavaScript rewrite with react, which will deprecate your code in some time.
It might be helpful for your case to check the #167 pull request which introduces similar functionality.
I think I understand. I thought React wasn’t MVC and so did not go well with the mental image I had given the fact that the PHP of Carbon Fields relies heavily on nested associative arrays. I’m hoping that the React implementation of Carbon Fields can expose documentation about the elements placed in the DOM and how to use JQuery to access them. And please be sure to document how to get the number of items in a complex field.
Stuart Simon
Graphics Specialist
LSU Human Development Center
411 S Prieur St
New Orleans, LA 70112
http://www.hdc.lsuhsc.edu/
From: Plamen Kostadinov [mailto:[email protected]]
Sent: Tuesday, January 31, 2017 10:36 AM
To: htmlburger/carbon-fields carbon-fields@noreply.github.com
Cc: Simon, Stuart A. ssimo3@lsuhsc.edu; Mention mention@noreply.github.com
Subject: Re: [htmlburger/carbon-fields] Custom validation/Getting the Backbone model (#199)
EXTERNAL EMAIL: EVALUATE
Hi @ssimo3lsuhschttps://github.com/ssimo3lsuhsc ,
If you need to create a custom field with custom validation, you can check the next 2 resources:
However, please note that there is under development a full JavaScript rewrite with react, which will deprecate your code in some time.
It might be helpful for your case to check the #167https://github.com/htmlburger/carbon-fields/pull/167 pull request which introduces similar functionality.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/htmlburger/carbon-fields/issues/199#issuecomment-276416211, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATRYOEUsZvXYSziv4iJ9Xgt0Q9hX4FU6ks5rX2MKgaJpZM4Lw5JA.
I’m willing to share at this point what I’m trying to accomplish. If my e-mail server will let me, I will attach a PHP file that contains the code for my Carbon Fields meta boxes and the validation that I need. I understand the mechanics of validating fields by relating them to fixed values. What I need is to expose the mechanics of how to validate fields against other related fields, whether those fields be children, parents, siblings, uncle and nephew, or cousins in the DOM.
Stuart Simon
Graphics Specialist
LSU Human Development Center
411 S Prieur St
New Orleans, LA 70112
http://www.hdc.lsuhsc.edu/
From: Simon, Stuart A.
Sent: Tuesday, January 31, 2017 11:00 AM
To: 'htmlburger/carbon-fields' reply@reply.github.com
Subject: RE: [htmlburger/carbon-fields] Custom validation/Getting the Backbone model (#199)
I think I understand. I thought React wasn’t MVC and so did not go well with the mental image I had given the fact that the PHP of Carbon Fields relies heavily on nested associative arrays. I’m hoping that the React implementation of Carbon Fields can expose documentation about the elements placed in the DOM and how to use JQuery to access them. And please be sure to document how to get the number of items in a complex field.
Stuart Simon
Graphics Specialist
LSU Human Development Center
411 S Prieur St
New Orleans, LA 70112
http://www.hdc.lsuhsc.edu/
From: Plamen Kostadinov [mailto:[email protected]]
Sent: Tuesday, January 31, 2017 10:36 AM
To: htmlburger/carbon-fields <[email protected]carbon-fields@noreply.github.com>
Cc: Simon, Stuart A. <[email protected]ssimo3@lsuhsc.edu>; Mention <[email protected]mention@noreply.github.com>
Subject: Re: [htmlburger/carbon-fields] Custom validation/Getting the Backbone model (#199)
EXTERNAL EMAIL: EVALUATE
Hi @ssimo3lsuhschttps://github.com/ssimo3lsuhsc ,
If you need to create a custom field with custom validation, you can check the next 2 resources:
However, please note that there is under development a full JavaScript rewrite with react, which will deprecate your code in some time.
It might be helpful for your case to check the #167https://github.com/htmlburger/carbon-fields/pull/167 pull request which introduces similar functionality.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/htmlburger/carbon-fields/issues/199#issuecomment-276416211, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATRYOEUsZvXYSziv4iJ9Xgt0Q9hX4FU6ks5rX2MKgaJpZM4Lw5JA.
Custom validation for existing fields would be great. Unfortunately, the users in my project get stucked without proper validation.
For instance: In my project there is a part where the user can create custom taxonomies with the help of complex fields. The internal taxonomy name is only allowed to contain lower cases characters, _ and some more special characters. - is not allowed, but that's what they often enter...

2.0.0 has been released which allows you to hook into forms' submit event (normal jQuery usage) and add your own client-side validation by utilizing the new JavaScript API to get/set field values, for example.
More info here: https://carbonfields.net/docs/advanced-topics-javascript-api/?crb_version=2-0-0
I have seen and read both the pages about Custom Validation and the JavaScript API, and can only conclude that you have not tested it using the behavior of an end user. The MOST IMPORTANT THING TO ENSURE in custom validation from a user's point of view is that they can see error messages with their own eyes. You have already done this with built-in validation. In order for custom validation to be user-friendly, your API needs to expose the methods that add, remove, show, and hide error messages on particular fields.
I am going to see if after I type this and click the "Comment" button, I can reopen the issue. At some point I expect to see .addError(field, msg) and .removeError(field, msg) or something similar.