Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Best practice on getting elements from controller

$
0
0

Hi all,

I'm new to Alloy and Titanium and I've been thinking if there is a way to select the elements on a view through their tag name or class name.

I have a simple use case as an example, that is a form validation. If the form is invalid a red border should show in the invalid fields. Here is an example view:

<Alloy>
    <Window>
        <View class="text-container">
            <TextField></TextField>
        </View>
        <View class="text-container">
            <TextField></TextField>
        </View>
    </Window>
</Alloy>
So, in the controller, how can I get all the TextField elements?

In the web development world that would be a document.getElementsByTagName(). I know you can access IDs but they are unique, so if I have 6 TextFields in a screen I should make then have 6 different IDs and reference then individually, which is really bad in a maintenance and algorithm point of view.

Traversing thorught the children of a parent element look as bad since there may be many levels of Views until we get to a TextField. In a specific case the TextField is inside a require.

Any thoughts?

Application type: mobile Platform & version: iOS, Android


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>