Comments (18)
Related from JSON Schema: http://json-schema.org/draft-07/json-schema-validation.html#rfc.section.10.1
from json-editor.
Hello @schmunk42 , thanks for pointing it out.
Does that mean that you are open to implement it ??
from json-editor.
I would also like to hear some other opinions ... but in general it looks useful.
I think I won't be able to do it, but PRs are generally welcome.
from json-editor.
To be clear I understand: is the proposal to use the "examples" property (I imagine picking the first entry in the array)?
The other properties (title, description, default) are already in use.
from json-editor.
The other properties (title, description, default) are already in use.
@eduo how can I set a description ? I didn't saw anything on the documentation
from json-editor.
"properties": {
"campaignVendor": {
"type": "string",
"id": "/properties/campaignVendor",
"title": "Vendor",
"default": "763",
"format": "text",
"description": "INFO: Vendor para el que se hará la campaña."
}
from json-editor.
Many thanks for the example.
How did you noticed that you can use it that way? There is not a single line of documentation about it
from json-editor.
No, there isn't :)
It's in the spec so I tried it. I later saw that the JSON2Schema tool creates placeholder fields for it as well:
https://github.com/jdorn/json-editor/wiki/JSON2Schema
For the above it would show this:
You can see how it expands to the full schema and puts placeholders for several fields (title, description, etc.) as well as setting default values.
It doesn't do complex types, I think (checkboxes, multi-selects, dropdowns) but it works to get a basic template to expand manually.
{
"$schema": "http://json-schema.org/draft-04/schema#",
"additionalProperties": true,
"title": "MyJSON",
"definitions": {},
"type": "object",
"id": "https://niebert.github.io/json-editor",
"defaultProperties": [
"campaignVendor"
],
"properties": {
"campaignVendor": {
"type": "string",
"id": "/properties/campaignVendor",
"title": "Title of 'root.campaignVendor' Type: 'string'",
"default": "763",
"format": "text",
"description": "An explanation for 'root.campaignVendor' about the purpose of string instance with editor path 'root.campaignVendor'."
}
}
}
from json-editor.
I was looking around at how to integrate placeholders and a non-schema option would be to replicate the "startval" parameter of the constructor loading the placeholders in the same way default values can be loaded today.
from json-editor.
Hello again @eduo,
Thank you very much for sharing your findings.
I'll try them tonight.
The tool you are using looks very promising too. I didn't heard about it neither, thanks for that too.
Now the only thing missing are placeholders and a easier way to style the form.
Regards.
from json-editor.
Sadly, I can't tackle this as a PR at all right now, but I hacked an ugly way to add placeholders in my local copy until either somebody can do it better or I have the time. This is a 5-minute hack written from an iPhone since this was a hard requirement and the deadline was upon us:
At the end of the main postBuild, right after "this.onWatchedFieldChange()":
if(typeof this.input != 'undefined'){this.input.placeholder = getPlaceholder(this.input.name,this.jsoneditor.options.placeholders);}
This calls the getPlaceholder function, which I tacked at the end:
function getPlaceholder(thisName,placeholders){
holders = [];thisName.replace(/\[(.+?)\]/g, function($0, $1) { holders.push($1) });
thisHolder = holders[0];
return placeholders[thisHolder];
}
What I do then is that I set-up the placeholder json in a similar way to the default value json, and then call it from the constructor:
let campaignRequestVal = {"campaignStartsOn": "Quotation","campaignEndDate": "2018-03-01"};
let campaignRequestPlaceholder = {"campaignVendor": "Vendor ID#","campaignEndDate": "YYYY-MM-DD"};
var editor = new JSONEditor(document.getElementById('ticketForm'),{"schema": inputSchema, "startval": campaignRequestVal, "placeholders": campaignRequestPlaceholder, "form_name_root": "campaignRequest"});
This gets the job done, but I don't think it'll hold up for advanced or complicated set-ups.
from json-editor.
I just extended the string editor type, and added placeholder support like this:
JSONEditor.defaults.editors.stringextended = JSONEditor.defaults.editors.string.extend({
build: function () {
this._super();
if(!this.input) return;
// Add placeholder support
if (this.schema.options && this.schema.options.placeholder) {
this.input.setAttribute('placeholder', this.schema.options.placeholder);
}
}
});
// Add editor resolver
JSONEditor.defaults.resolvers.unshift(function(schema) {
if(schema.type === "string" && schema.format === undefined) {
return "stringextended";
}
});
from json-editor.
I completely missed this. I'll try it out and comment.
How should newlines in placeholder for textareas be represented here so they show as newlines as well in the textarea placeholder?
from json-editor.
I completely missed this. I'll try it out and comment.
I added the same functionality as I described above, in the datetime editor. You can see it in this example https://rawgit.com/json-editor/json-editor/master/docs/datetime.html
How should newlines in placeholder for textareas be represented here so they show as newlines as well in the textarea placeholder?
Without having to resort to JavaScript hacks, i think the only way is to add linefeeds to the text.
Like in this example: https://codepen.io/helloheesu/pen/MarzrW
from json-editor.
Option for placeholders
{
"title": "Person",
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string",
"options": {
"inputAttributes": [{
"name": "placeholder",
"value": "your name here..."
}]
}
}
}
}
from json-editor.
@germanbisurgi This info should be added to the documentation otherwise no one will know of the feature.
But why is it an array with objects? Wouldn't it be much simpler and easier to setup if it was just an object?
So instead of:
"inputAttributes": [{
"name": "placeholder",
"value": "your name here..."
}]
It would just be:
"inputAttributes": {
"placeholder": "your name here...",
"class": "blahblah"
}
And then change the code to this:
var inputAttributes = this.schema.options.inputAttributes;
for (var key in inputAttributes) {
if (inputAttributes.hasOwnProperty(key)) {
this.input.setAttribute(key, inputAttributes[key]);
}
}
from json-editor.
bump
from json-editor.
Closed by #255
from json-editor.
Related Issues (20)
- Hidden fields with dependencies disappear after setValue() HOT 1
- [question]How can i hide false ouput value on checkbox. HOT 2
- [question] How to get updated schema from json-editor after adding object field HOT 10
- Can I Do Dependencies Only On the Default Value And Enum? HOT 1
- [bug]select2 setValue report a error and not select it HOT 8
- Starrating format isn't working properly HOT 1
- bug/regression: bool or number value does not show when remove_empty_properties=true and use_default_values=false
- Can Do a "WACTH" To Another Root "JSON Editor". HOT 4
- Auto generate schema for simple cases HOT 5
- Support for chained / nested watch HOT 2
- Add meta-data (schema builder) example HOT 1
- Validation of datetime-local fails when oneOf is used HOT 3
- An error occurs when a dependency is defined after the field that depends on it HOT 1
- Dependent field does not update when watched field changes HOT 1
- Failure to parse schema with "default": null due to unhandled exception in browser console
- select2 doesn't refer enumSource of item in array. HOT 12
- How do I add my syntax highlighting to Ace Editor? HOT 1
- test
- Enum wont be selected on load if it not the first element HOT 1
- Dependencies with false values not fullfilled HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-editor.