[Blaze] Patterns with Forms and Atomicity of Inputs

Hello,
I am currently working with Blaze to do a dynamic and long formular and I would like to save my input data from the UI.

  1. – Logic handler Template
  2. – A lot of Dynamic Inputs / Select / checkboxes / radio buttons

Since I want my form components to be reusable in other forms, I want them to know how to acces to their own data. So each element has a function getUIData(),

var getUIData() = function(){
// here take the data with jQuery
return value;
}

Also, I need my logic handler parent template, to call the function of his children. Is there a way to achieve that ?

Something like:

foreach(Template.Logic.getNumberOfChildrenTemplate("form-myform-element")){
array[name] =  Template.Logic.getChildrenTemplate("form-myform-element").getUIData();
}

Is it possible to call the helper from parent template ?

Don’t try that :wink:

If you try to do what you describe / desire in Blaze, it will become a dead end, if not extremely complex.

Look no further, use https://viewmodel.meteor.com . It’s all you need now and possibly in a long future. Plus the author is extremely responsive that you always get improvements, fixes and new features.

A few quick examples…

Referencing a single child from the parent:

<template name="parent">
  {{> child ref='myChild'}}
</template>
Template.parent.viewmodel({
  callChild: function() {
    this.myChild.doSomething();
  }
})

Calling a parent function from the child:

<template name="parent">
  {{> child }}
</template>
Template.child.viewmodel({
  callParent: function() {
    this.parent().doSomething();
  }
})

Referencing all children from the parent:

<template name="parent">
  {{#each collection }}
    {{> child }}
  {{/each }}
</template>
Template.parent.viewmodel({
  callChildren: function() {
    this.children().forEach(function(child) {
      child.doSomething();
    });
  }
})