Meteor dynamic input fields - meteor

I'm looking for a way to create dynamic input fields in Meteor.js. I've chosen not to use Aldeed's Autoform for greater control over the code. From front end point of view I have no issues to add dynamic fields with +/- button to add and remove fields. What I'm struggling with is the insert statement on the back end. How can one add dynamic insert in Meteor.js? Cheers!

Essentially you need a reactive array of element that's rendered to the DOM via {{#each}} ... {{/each}}. When the array changes the DOM would re-render.
There's no need to create your own reactive array, there's one here with an example that does exactmy what you're asking for:
http://reactivearray.meteor.com/
However I'd recommend going one step further and using the ViewModel package for this (by the same author). Here's an example which shows how to use it to insert fields:
http://viewmodel.meteor.com/#contacts
Tim

Thanks Tim, these are both pretty useful. I'm using Collection 2 so decided to use objects ('object.$'). This is easy solution for me. cheers.

Related

Antd - Form.List prefill

I use https://codesandbox.io/s/wonderful-lichterman-br63z and would like to prefill items (with specific data) in the form.
What is the best approach to do this ? I have entries in redux which I would like to get into this dynamic form prefilled.
I know that I can create placeholders, but how can I add specific data ?
What really makes it difficult is that I need a relation between a rendered item and an entry from a data array.
Please see:
https://codesandbox.io/s/blissful-hopper-4e6i0?file=/index.js
I hope the solution works for your use case. You will need to replace my hard-coded default values with desired initial values from your redux store. Cheers!
Update:
I found a better implementation. Turns out add method allows one to set a dynamic fields defaultValue
See:
https://codesandbox.io/s/fervent-morning-c9vhk

create objects dynamically according database values

I have a Flex project. I want to dynamically create mx.controls.Image objects and add them to the display. However, the number of images and it properties deponds on the value stored in a database. Hence, I have to connect to the database,read the values for data table, then create objects dynamically according the values.
Then, I wonder if this is possible and how to do this.
Thanks in advance.
Felix
Just try declaring a variable as *.
Like var any:*; And check always for null. So it will take any type of value.
Hope it will help.

Datagrid using fuel ux

I'm using Fuel ux data grid for showing records in a table format. I need some additional functionality. I have to create a link button inside the data grid each row. Please anyone tell me is it possible? If yes let me know the solution. Thanks in advance
This is possible - Adam Alexander has some sample code here: https://github.com/adamalex/fuelux-dgdemo/blob/master/index.html#L129-134
The general process is to create a formatter function that can take the returned data from your data source and apply a transformation to create html, text, or other content as needed. Note that the column named 'image' doesn't reference anything that exists in the original data, but the property 'image' on item is created by the formatter function so it can be rendered.
The above code was used for this article, if you want to see it in action: http://dailyjs.com/2012/10/29/fuel-ux/

Combine two views into one view

I have two views that I would like to combine into one.
The first view shows all items of X where company ID = Y. This is to give preferential sort to the client first, and then everyone else.
So I created a second view, all items of X, where company ID != Y.
I created it as an Attachment to attach to the first view, but I don't think I got the intended result.
How can I combine these views so the first view results are listed first, and then the second view is too, using the same pager, filters, and arguments?
Is there any way of achieving this without programming it?
From a MySQL point of view, the order-by-field syntax would be the appropriate way to handle this. Example:
SELECT * FROM tickets ORDER BY FIELD(priority, 'High', 'Normal', 'Low');
It would be great if there is a module that add this kind of functionality to Views, but AFAIK, it does not exist.
If you want to solve this without programming, I think you can use the rules module to automatically set the 'sticky' checkbox on nodes where company ID = Y. With that in place, you can order the View on the sticky value.
Along the lines of the 'sticky' idea, if you didn't want to override that, maybe you could add a checkbox field to the company type -- isClient. Make it false for everyone except the client, and sort by that.
I haven't done this, but maybe you need to create both versions as attachments, and attach them both to another display...?
for drupal 5 there was views union. Someone started something for D6, but I don't know how far they got.
http://drupal.org/node/275162
Create the second view as an attachment and attach it to first.
Set all Inherit arguments, Inherit exposed filters and Inherit pager to Yes.
how is the client parameter passed to the view? as an url argument? if so, you can create your second view like i outline here and then select the exclude the argument option on the appropriate location.
usually the easiest way to achieve this is with a small hook_query_alter, but that requires a small amount of programming.
A little bit later... but I've found a better solution using only the Views module:
Create a Block View with that shows the first list that you need ("all items of X where company ID = Y")
Create another View that must be a "Page view" with the second list (all items of X, where company ID != Y)
In the "HEADER" settings of this second view, click "Add" and select "Global: View area".
In the "View to insert" list, select the first you have created (and check "Inherid contextual filters" if you are using it)
And that's it!

D6: how to get at node fields in preprocess_page()?

i created a view that displays my homepage fine but now a modification is needed: i load 2 fields (images) in my view but need to only display one of those, depending on the value of a third (date) field and today's date. if date field is later than today, show image y and if its earlier than today show image x. this kind of logic cant be done in a view.
so in my template.php id like to output x or y as $vars['img'] in the preprocess_page function. im just wondering, how do i get at the values of those fields? its not a node but a list of node teasers.
the function gets passed &$vars but a print_r of those just shows the html output.
custom sql seems not the way to go.
when i load the view, i just get the html it outputs but (i think) i need the raw data to make the date comparison.
thanks for any pointers!
I'm sure there are some ways to do this, some more hackier than others. I would:
Make a template specific to your view
Create a preprocess function for the view and create a boolean variable, by checking which img that should be displayed.
Lastly I would alter the template slightly by making an if statement that checks if it should display img x or y.
This solution is pretty easy and straight forward, the downside is that it's not completely general as you most likely will need to know the names of the cck field names you are using. It's doubtful you would be able to generalize this anyways.
Edit:
To clarify a bit. You can look at the general views template that's being used, it will give you some insight as to how views prints the different fields. Generally getting at the fields is usually not a big problem when you have the $node object. The reason is that cck adds the fields to the $node object so you can access it there. I believe you can do something in the line of $node->field_[the_name] to get to the field. I would suggest that you use the devel module if you don't already and do a dpm($node) somewhere in the template where you loop through the nodes. That will enable you to see what has been defined on the $node object. It shouldn't be a big problem to print the img from there.
How about using preprocess_node() instead?

Resources