Display form inputs for unpopulated properties
See original GitHub issueGeneral information
- json-editor version: latest
Expected behavior
I’m not sure if the library is supposed to be able to do this, but here is what I am trying to do:
- Use jsonschema to describe a form with many fields
- Seed the form using
startval
with values some (but not all) fields - Display the entire form, including all empty fields
Here is the code that I’ve tried:
<div id="holder"></div>
<script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.min.js"></script>
<script>
var schema = {
"foo": {
"type": "object",
"title": "Foo",
"properties": {
"bar": {
"type": "string",
"title": "Bar"
},
"baz": {
"type": "string",
"title": "Baz"
}
}
}
};
var settings = {
"foo": {
"bar": "Hello world"
}
};
var editor = new JSONEditor(document.getElementById('holder'), {
schema: schema,
startval: settings
});
Actual behavior
I was hoping to see “Bar” filled in with “Hello world” and “Baz” as an empty text input. But so far I am only seeing “Bar” filled in with “Hello world”. The “Baz” field does not appear.
Any advice would be greatly appreciated, if there is an easy way to get what I’m looking for. Thank you!
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
<input>: The Input (Form Input) element - HTML
<input> types · button, A push button with no default behavior displaying the value of the value attribute, empty by default. · checkbox,...
Read more >Don't submit form if inputs are empty - Stack Overflow
You wrap a form around all your inputs, give the form a name like name=form and set the required attribute on all inputs....
Read more >Chapter 18 Forms and Form Fields - Eloquent JavaScript
The files property of a file field element is an array-like object (again, not a real array) containing the files chosen in the...
Read more >Forms in HTML documents - W3C
Several checkboxes in a form may share the same control name. Thus, for example, checkboxes allow users to select several values for the...
Read more >ASP.NET Core Blazor forms and input components
For input components in a form with an EditContext, the default validation behavior includes updating the field CSS class to reflect the field's...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @brockfanning, it’s a common misconception that fields in the ‘required’ array must have data. It only means ‘required’ properties must be included in the data object, not that they have data in them. If you want to control what data is them, you’d give them a type, minLength/maxLength validations, etc. All that can be seen in the schema definition/validation documentation on the site I provided.
@kameelyan Aha, thanks very much. The problem you point out in my schema explains why
required_by_default
andshow_opt_in
did not appear to be changing anything.I think I may be trying to use the library in a way that was not intended - to display a form to non-technical users. In my case, I want all the properties to appear, but I don’t want them to be required; and because the users are non-technical, I don’t want users to have to go into “Object properties” in order to see them (in fact to prefer to hide those buttons altogether).
I’m trying a workaround where I rely on
default
in the schema, in combination with custom code, in order to force these non-required properties to appear as form elements. However it’s not ideal.I’m wondering if my use-case is too far outside the intended function of the library. If you agree, feel free to close this ticket. If not, do you think there should/could be a config setting which would force all properties to appear, even if unpopulated and non-required?