GithubHelp home page GithubHelp logo

Comments (18)

schmunk42 avatar schmunk42 commented on May 12, 2024

Related from JSON Schema: http://json-schema.org/draft-07/json-schema-validation.html#rfc.section.10.1

from json-editor.

danielo515 avatar danielo515 commented on May 12, 2024

Hello @schmunk42 , thanks for pointing it out.
Does that mean that you are open to implement it ??

from json-editor.

schmunk42 avatar schmunk42 commented on May 12, 2024

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.

eduo avatar eduo commented on May 12, 2024

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.

danielo515 avatar danielo515 commented on May 12, 2024

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.

eduo avatar eduo commented on May 12, 2024
"properties": {
	"campaignVendor": {
		"type": "string",
		"id": "/properties/campaignVendor",
		"title": "Vendor",
		"default": "763",
		"format": "text",
		"description": "INFO: Vendor para el que se hará la campaña."
	}

}
screenshot 2018-02-20 13 23 26

from json-editor.

danielo515 avatar danielo515 commented on May 12, 2024

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.

eduo avatar eduo commented on May 12, 2024

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:

screenshot 2018-02-20 13 39 50

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.

eduo avatar eduo commented on May 12, 2024

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.

danielo515 avatar danielo515 commented on May 12, 2024

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.

eduo avatar eduo commented on May 12, 2024

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.

pmk65 avatar pmk65 commented on May 12, 2024

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.

eduo avatar eduo commented on May 12, 2024

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.

pmk65 avatar pmk65 commented on May 12, 2024

@eduo

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.

germanbisurgi avatar germanbisurgi commented on May 12, 2024

Option for placeholders

{
	"title": "Person",
	"type": "object",
	"required": [
		"name"
	],
	"properties": {
		"name": {
			"type": "string",
			"options": {
				"inputAttributes": [{
					"name": "placeholder",
					"value": "your name here..."
				}]
			}
		}
	}
}

from json-editor.

pmk65 avatar pmk65 commented on May 12, 2024

@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.

pmk65 avatar pmk65 commented on May 12, 2024

bump

from json-editor.

schmunk42 avatar schmunk42 commented on May 12, 2024

Closed by #255

from json-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.