Hi Everyone,
I'm currently working on a medialibrary. The idea is that the app shows several dynamic fields obtained from the database.
Some fields may be of image type, so in order to select an image, an image library formatted into a tableview is shown (in a new window). When opening this window the fieldId and a callback is passed.
Once an item is clicked, it calls the callback. In this callback it attempts to set the value of the dynamic textfield. This is where it seems to fail.
The console recoqnizes the object as a TiUITextField, but it does neither react to .value or .setValue.
Does anyone have an idea what I'm doing wrong and how I could solve this?
Kind Regards, Lars
Relevant source code:
XML Fields:
<View> <ScrollView id="dynamicFields" showVerticalScrollIndicator="true" scrollType="vertical" layout="vertical"></ScrollView> <ActivityIndicator id="activityIndicator" style="Ti.UI.iPhone.ActivityIndicatorStyle.BIG" height="Titanium.UI.SIZE" width="Titanium.UI.SIZE" visible="true" platform="ios" /> <ActivityIndicator id="activityIndicator" style="Ti.UI.ActivityIndicatorStyle.BIG_DARK" height="Titanium.UI.SIZE" width="Titanium.UI.SIZE" visible="true" platform="android" /> </View>Controller Fields:
function drawImageSelector(fieldData) { var view = Ti.UI.createView({ height : Ti.UI.SIZE, fieldId : fieldData.fieldId }); var label = Ti.UI.createLabel({ text : fieldData.name, left : 10, font : { fontSize : Alloy.Globals.FONT_SIZE_NORMAL } }); var textField = Ti.UI.createTextField({ id : "f" + fieldData.fieldId, maxLength : fieldData.maxLength, right : 60, editable : false, hintText : L("label_noImageSelected"), textAlign : "right", color : "#000", font : { fontSize : Alloy.Globals.FONT_SIZE_NORMAL }, height : 30 }); var button = Ti.UI.createButton({ backgroundImage : "/images/picture_icon.png", right : 10, width : 50, fieldId : fieldData.fieldId, }); button.addEventListener("click", function(e) { var id = e.source.fieldId; var field = null; _.each(resultContainer.fields, function(object) { if (object.fieldId == id) { field = object; } }); var data = { field: field, type: "photo", callback: function(result) { console.log("Callback triggered with result: " + JSON.stringify(result)); _.each($.dynamicFields.children, function(child) { if (child.fieldId == result.fieldId) { console.log("Found ya"); console.log(child.children[1]); child.children[1].setValue("asdfasdfasdfasdf");//result.value; console.log(child.children[1].value); } }); } }; var controller = Alloy.createController("medialibrary/library", data).getView(); if (OS_ANDROID) { controller.open(); } if (OS_IOS) { G.navMenu.openWindow(controller); } }); view.add(label); view.add(textField); view.add(button); $.dynamicFields.add(view); }XML Library:
<TableView dataCollection="medialibraryitems" top="6"> <TableViewRow id="{id}" filePath="{filePath}" onClick="selectMedia"> <Label class="rowItem" text="{filePath}" /> <ImageView image="{filePathThumb}" height="20" width="20" right="5" /> </TableViewRow> </TableView>Controller Library:
function selectMedia(e) { console.log(e.source.filePath); args.callback({ fieldId: args.field.fieldId, value: e.source.filePath }); $.library.close(); }Output:
[INFO] : \\nas\Photo\Nature.jpg [INFO] : Callback triggered with result: {"fieldId":5970,"value":"\\\\nas\\Photo\\Nature.jpg"} [INFO] : Found ya [INFO] : [object f5970] [INFO] :