How to add more textfields in a view on clicking a button in the same view in sproutcore?
I have a sliding pane with particular number of textfields. On clicking a button, I need to add more number of text field in the same view.
Or,
I should be able to select the number from a select button view and show those many number of textfield in the same view.
I would recommend using a SC.ListView for this purpose.
You should have a SC.ArrayController whose content is an array containing objects that represent each text field. This may be as simple as something like this:
Next, you'll create your SC.ListView and bind it's content to the controller, and create the exampleView whose content is bound to the
somePropertyproperty of the objects:Now, when you click the "Add Text Field" button, it will add a new object to the controller array which will automatically re-render the list view with the new object and hence, the new text field.
A couple of notes:
This uses a SC.ScrollView in conjunction with the SC.ListView, you will almost always want to do it this way.
Since we are using standard bindings (not SC.Binding.oneWay()), editing the text fields will automatically update the
somePropertyproperty in the objects inMyApp.myControllerand vice versa: if you update the value via some other means, the text field should automatically update as well.This should not be used for a large list as using the
childViewsmethod of view layout can be slow. If you need performance, you should change theexampleViewto a view that overrides the render() method and manually renders a text input and sets up the proper change events and bindings.Lastly, I can't remember if the proper syntax for the text field's
valueBindingisparentView.content.somePropertyor.parentView.content.someProperty(notice the period at the beginning). If the first way doesn't work, try adding the.and see if that works.