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

Set the title map of an select field that is inside of an array #788

Closed raquintero closed 7 years ago

raquintero commented 7 years ago

Hello, I have a dropdown field that needs to be changed on the fly. aka dynamically. And this field is inside an array. Is there an example of this somewhere?
If not, can someone point me to an example/documentation showing how to update the form model and reset the default titlemap field? I am not sure the proper sequence or when in the schema/form building or loading process where I can do this?

Thanks!

Anthropic commented 7 years ago

@raquintero if you google for angular-schema-form dynamic select you will find an add on that already does what I think you want to do.

raquintero commented 7 years ago

@Anthropic Thanks, I'll have to take a look. Looks simple enough, I hope.
Side note, it seems that not every component has the same available attributes available. For instance, if every component could take an onClick and OnChange event, and you could get the array index, modelVal, form, as well as absolute path, then pretty much most issues will be solved. Is there an inherent reason why index values, or at least absolute path to an object is not available? Especially using a library like lodash would make it incredibly easy to save, modify, etc values with simple onChange or onClick events. This has been my biggest stumbling blocks and is litterally forcing me to spend weeks on what should be the most trivial of tasks. It's getting quite frustrating actually. Anyway, thanks for the lead.

raquintero commented 7 years ago

@Anthropic Thanks for the link. I couldn't use the dynamic select. I broke all of my existing select boxes, and there were too many dependencies to debug. I just need the way to pass the current index on an onChange event. I did the update for the onClick having the Array indexes, (haven't gotten around to using it yet), but I can't add an onClick to the input fields, without completely re-creating the directives, and admittedly I'm am not a 'Directive' expert.

Anthropic commented 7 years ago

@raquintero the main problem is that the way arrays are handled is to use the angular repeat to manage them which then appends a predefined template built up from the form definition. This was done by the creators to make it much much faster than it was before that, however the trade off was that the scopes no longer had knowledge of their parents in the same way as children of an object do. Trust me this is causing me as much pain as you so I am trying to resolve it asap :)

raquintero commented 7 years ago

@Anthropic Hi, any progress with allowing form fields to maintain a copy of the index that it resides in?
Also, directly related to the original question, Is it possible to update the enum/titleMap of a select field during creation?
My hope is:

  1. I have a custom bootstrap template (an addOn) that adds an attribute, called setTitleMap, which would be a name of a function that is created in my Controller
  2. During the Directive creation stage, in the link function, I can see if this attribute is set.
  3. If the attribute is set, I call the eval() function on this string, and the call it
  4. And then I can set the TitleMap with the return value

IS this possible, or will it require a complete over write, like the angular-schema-form dynamic library does?

I need to set a select field dynamically, when the form is rendered, and cannot wait for an 'onChange' event. I was hoping to perform this with the sf-render-finished event, but that didn't work. I'm at my whits end with fighting this library, and I'm going to have to abandon this soon if these trivial issues can't be resolved.

For posterity's sake, I am again asking if, in a form that contains arrays and nested arrays, if there is a way to: Set the titleMap of a select field dynamically, before the user sees it? On an onChange event, set another fields value. Target field could be a combination of two fields, and the target value could be in the same array, or a nested array value.

Anthropic commented 7 years ago

@raquintero angular-schema-form-external-objects is my own extensions for updating a titleMap dynamically and includes an option to get data from the form scope rather than externally, I don't think it would be too hard to modify that to do what you want to do. I don't know if you can do it in a day, but you could definitely do it.

nicklasb commented 7 years ago

@raquintero Hi, maintainer of ASFDS here, remember you only need the dependencies for the select you need. Also, I am interested in what way it broke things for you?

Anthropic commented 7 years ago

Please re-open if you do not feel the question has been answered sufficiently or you have more to add.