Dynamic fields in one schema with autoform?


#1

Hi,

I’m using autoform, and I am trying to see if we can have fields displaying and hiding depending on the value of other fields… I know it can be done using a second schema, but I need to have it in one… can it be doen? Or am I out of luck? Is there maybe a plugin?..

Or is it possible in one schema, and am I reading the field-values example wrong? :wink:

regards,

Paul


#2

Not sure how you mean, but something like this?

{{#autoForm  type="update" doc=this collection="myColl"}}
        {{#each afFieldNames}}
            {{#if myHelperFunctionThatDecidesVisibility this.name}}
             {{> afQuickField name=this.name}}
            {{/if}}
        {{/each}}

#3

Hi Ralof,

thank you for your answer, but it is not quite what I was looking for. If you look at the examples, you can for instance do this:

   {
   level1: {
      type: Array,
      optional: true
   },
   "level1.$": {
      type: Object
   },
   "level1.$.level2a": {
      type: String
   },
   "level1.$.level2b": {
      type: Array,
      optional: true
   },
   "level1.$.level2b.$": {
      type: Object
   },
   "level1.$.level2b.$.level3a": {
      type: String
   },
   "level1.$.level2b.$.level3b": {
      type: String
   }
}

which would give you a dynamic array, enableing you to add and delete elements on the fly. This kind of dynamic behavour would suggest that it would be possible to show/hide fields based on the value of another field. But I have not been able to find a example - except the one I linked to in the OP. I use/can use only one schema, so I am looking to a alternative…

regards,

Paul


#4

Is it the “displaying and hiding” feature will happen during user input? If yes, you may take a look on this autoform demo


#5

Hi ajaxsoap,

yes, I know that example. However, my current setup uses a form where the schema is dynamically added to the form during runtime. EG: I need a schema where there is only the schema and a single form-entry in the template. I am not adding extra template-lines during runtime. So: I am trying to get to this functionallity, while having only

{{> quickForm id="demo" schema=schemaFromJSON type="method" meteormethod="demoSubmission"}}

in the template… I’m not sure if this is possible. But for instance the array-function is working this way (adding “subforms” reactivly to user input too… so I was hoping this could be done for this function too :smile:

Thanks for your answer anyway - it is good to know people very willing to help! :innocent:

Regards,

Paul


#6

Yeah, my mistake i haven’t read thru your post link.

I love Meteor so as the vibrant community!

I think you should file this directly in autoform repo issue tracker. Maybe Aldeed might help you.


#7

How would you go about using quickform as subcategories for the dynamic field, though? This schemas have nothing that identify them to go if this field is selected auickform 1, else quickform 2.


#8

In the end, I ditched Autoform for JSONForm in this instance. Of course, it is not integrated into the Meteor framework like Autoform is, but using it was far more easy than wrestling with Autoform in this case :slight_smile:


#9

you took inspiration from somewhere? is there a guide


#10

There is not really a guide to use this in Meteor, but the basics are not hard. You can check here. I store the schema just in a JS object, and put it to the library when I need it. The form generated by this lib will just pop up in a DIV. You can puth a JSON object along with it to fill it with data, and pick it up on submit. You can than use the result to object your data in you Meteor app. I found the examples very usefull.
If you need more pointers, you know where to find me :slight_smile:


#11

So if I wanted users to be able to create additional forms on top of the standard one, I’d probably like to use your approach instead of trying to define a schema on instance of document or something?


#12

It’s what I found easier… YMMV :sunglasses:


#13

Did you try to do ordering in either case? *sortable list


#14

what is ur usage of json-forms if its hosted somewhere or at least theres a repo.


#15

Hi,

no, there is no repro, but you can just download the JS and put it in your project; it’s easy. (I put it in /client/js.
I use the “array” type extensively, and that you can (re)order. I don’t know if it will fit your needs; you really need to try yourself. :slight_smile:

regarcs,

Paul


#16

So this solves for having user customizable forms (creating a schema for each document).