0
votes

I was creating a form on my app and it has validation. When a field is found invalid I show a red warning sign on the field (it's just a label).

Because I have many fields I've created a function that get the textfield object, does a Ti.UI.createLabel with my style, and top and left positioned by received object and add that to the page.

While this work perfectly, I got to think that it might not be the "correct" way to use Alloy. So I was wondering if I should have created an Alloy view (no controller needed since there's no logic), and that view will have the label (just label!) and tss file with the fixed style, and then get the view the "Alloy way" and add it to the page?

What is the best practice in such a scenario? I also think that alloy adds it's own controller code and inside creating the label like I do now - so it adds additional actions for js engine to perform? performance and memory consumption is of course my main concern.

1

1 Answers

1
votes

I think using Alloy way it's better for code maintenance. Later, if you want modify your Label, you just need to edit your TSS. In term of performance, i'm not sur there is a big difference (it's just a Label) and XML view is transform to Ti.UI.create finally.

If you have no JS logic to implement, you can use $.UI.create method to apply your TSS class to an element : http://docs.appcelerator.com/platform/latest/#!/api/Alloy.Controller.UI-method-create

var label = $.UI.create("Label", {
    classes: 'yourstyle',
    top : 30 //add other property like this
});
$.index.add(label);