json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 653 forks source link

Extend Decorator to view Input Model Immediately #846

Closed radvansky-tomas closed 7 years ago

radvansky-tomas commented 7 years ago

Hi I am using 3rd party decorator and I would like to add my own template which is in fact with type = range. Everything works fine.

But next step is to add some label/input to show currently selected value by range control.

I tried different combinations of sf-model, but none of them seems to work. Could you please post me to right direction ?

  <input sf-field-model="rangeModel"
           sf-changed="form"
           ng-class="form.fieldHtmlClass"
           ng-disabled="form.readonly"
           name="{{form.key.slice(-1)[0]}}"
           type="range">

    <input sf-field-model="rangeModel"
           type="number">

@json-schema-form/angular-schema-form-lead

Anthropic commented 7 years ago

@radvansky-tomas can you make a plunker demo of what you are doing so far?

radvansky-tomas commented 7 years ago

I am using for my forked version of Angular Ionic Schemaform Decorator: https://github.com/radvansky-tomas/angular-schema-form-ionic

This is more less generic question which you should be able to replicate with any decorator. Lets say that you have basic input text. And you want right next to it display

element bound to same model as is bound to that input.

This is what I am trying to achieve image

Anthropic commented 7 years ago

@radvansky-tomas ok I see, that's clearer for me, so what I would do is pass your model into a property of a directive and have the directive controller handle the update of your model value, you don't have to do it all in the template alone, you can add your own directive or controller to manage your template and pass things to it.

In other words your two separate items may both have code to lookup their parent element for the schema-form details and then share them from there. Does that make sense?

radvansky-tomas commented 7 years ago

@Anthropic Thank you very much for quick reply, but unfortunately I dont understand :(

Where exactly I can place code to control my elements ? In decorator.js file ? Or you want me to control it from "client" app ?

Anthropic commented 7 years ago

In the client app, you can add directives/controllers that use your template and the values set in it.

Say you have a tag structure like:

div ng-controller="myslider as vm" sf-model="model" sf-field
  slider ng-model="vm.value"
  input ng-model="vm.value"

You can have a controller that defines the value to be used in your child elements.

At the end of the day apart from a few values it is not much more than a standard angular template you can do whatever you like to it with the value it gets passed. I'm in Australia so sleep time now sorry.

radvansky-tomas commented 7 years ago

https://plnkr.co/edit/GNI0JS?p=preview

radvansky-tomas commented 7 years ago

Sorry It took my a while, I havent use this tool before

Anthropic commented 7 years ago

@radvansky-tomas sorry I lost track of this, did you sort it out yourself or did you still need me to look at it?

radvansky-tomas commented 7 years ago

Yes you can close it, i sorted it via sf-model

Anthropic commented 7 years ago

Great to hear! Thank you :)