Closed bmcbride closed 10 years ago
Do you have a full example schema?
It's working correctly. In JSON schema, required
just means the property has to exist. To require non-empty values, set minLength
to 1 for that property.
Okay, got it. Thanks again.
I know this issue has been closed, but is there scope for an enhancement here? The validation error "Value must be at least 1 characters long." isn't as user friendly as something like "A value is required here".
Also, a lot of web sites usually have a visual indicator for required fields, e.g. * after the form control, which speeds up form completion for the user. I know the required
property is being used for indicating that the property must exist -- maybe mustExist
would have been a better name -- but would a new property valueRequired
make sense, which would give a more specific error that the control has been left blank?
Great work on the editor, by the way.
:+1: for requirement enhancement.
I agree the property names are confusing, but required
and minLength
come straight from JSON Schema, so I can't change that. I can definitely change the error message though and look into adding an asterisk.
I changed the error message for minLength: 1
to Value required
.
I want to spend some time thinking about the best way to handle the asterisks before implementing that.
Awesome -- thank you.
Hello, @jdorn
I want to spend some time thinking about the best way to handle the asterisks before implementing that.
Has it been implemented?
Hello, @schmunk42, I assume since you referenced this in json-editor/json-editor#44 we can handle the issue here.
Also I have one somehow related question - according to the README I can specify my own CSS styles, but I cannot find the way to specify CSS classes for elements in json schema (if I could do it, I'd just use .form-group.required
class from bootstrap to handle the first issue)
If you want to specify your own styles with CSS, you can use barebones, which includes almost no classes or inline styles.
I am not too familiar with the code, I'd recommend creating a new issue at https://github.com/json-editor/json-editor/issues
The documentation says you can use custom styles but does not say you can use custom classes. When you using barebones JSON editor it uses almost no classes that can override your styles.
I looked in the source code looking for a feature that does what you want to do but I did not find anything. A solution could be, to extend the theme class and create a new theme for JSON Editor.
You can look in the original repository wiki:
@germanbisurgi, thank you for the suggestion, but it seems that I can't customize form elements this way, only DOM ones (like tables etc.) and it might happen that I'd like to pull one table to the right and another to the left in my form depending on the element which is rendered, or even something more sophisticated, so it would be nice if we had feature to add classes to json form elements, thanks for reply
I'm having some issues figuring out how to make a field required. I've tried the following, which adds
"required": ["comment"]
to the object after defining the properties, but that doesn't seem to work. Any guidance would be most appreciated. Thanks!