Results 1 to 12 of 12
  1.    #1  
    For some reason, the Mojo.Event.listen below in the setup fails and crashes the app. The try{} doesn't seem to work inside the setup so I can't figure out what the error is.

    When I move the code (with the "try") elsewhere, I get the error "target undefined," but I'm not sure if this is because it's not in the setup function. Just scratching my head as usual. Help?

    Code:
    MainAssistant.prototype.setup = function() {
    	//setup checkbox widget
    	this.checkAttributes = {
    		property: "value",
    		trueValue: "ON",
    		falseValue: "OFF",
    		//fieldName: 'checkboxstuff'
    	};
    	this.checkModel = {
    		value: "ON",
    		disabled: false
    	};
    	this.controller.setupWidget("complete", this.checkAttributes, this.checkModel);
    		//try {
    		this.checkbox = this.controller.get("complete");
    		this.checkboxCallback = this.checkboxCallback.bindAsEventListener(this);
    		Mojo.Event.listen(this.checkbox, Mojo.Event.propertyChange, this.checkboxCallback);
    	//} catch (e) {
    		//Mojo.Controller.errorDialog(e);
    	//}
    }
    MainAssistant.prototype.checkboxCallback = function(event){
    	this.showDialogBox("Checkbox value changed", "The value of the checkbox is now: " + event.value);
    }
    MainAssistant.prototype.showDialogBox = function(title,message){
    		this.controller.showAlertDialog({
    		onChoose: function(value) {},
    		title:title,
    		message:message,
    		choices:[ {label:'OK', value:'OK', type:'color'} ]
    	});
    }
  2. #2  
    If someone wants to learn to write this type of code where would someone start?
  3. #3  
    Code:
    MainAssistant.prototype.setup = function() {
    	//setup checkbox widget
    	this.checkAttributes = {
    		property: "value",
    		trueValue: "ON",
    		falseValue: "OFF"
    	};
    	this.checkModel = {
    		value: "ON",
    		disabled: false
    	}
    
    try {
    	this.controller.setupWidget("complete", this.checkAttributes, this.checkModel);
            
    	this.checkbox = this.controller.get("complete");
    	this.checkboxCallback = this.checkboxCallback.bindAsEventListener(this);
    
    	Mojo.Event.listen(this.checkbox, Mojo.Event.propertyChange, this.checkboxCallback);
    
    } catch(e) { Mojo.Controller.errorDialog("setup:",e); }
    
    
    }
    
    MainAssistant.prototype.checkboxCallback = function(event){
    
    	this.showDialogBox("Checkbox value changed", "The value of the checkbox is now: " + event.value);
    }
    
    MainAssistant.prototype.showDialogBox = function( title, message) {
    try {
    	this.controller.showAlertDialog ({
    		onChoose: function(value) {},
    		title: title,
    		message: message,
    		choices: [
    		   { label:'OK', value:'OK', type:'color' }
    		]
    	});
    } catch (e) { Mojo.Controller.errorDialog("showDBox:",e); }
    }
    Try something like that, i didn't test it but that should give you a better warning whats causing the issue, BTW IMHO its kinda easier to see the issues if you do Mojo.Log.(error|info|warn)("functionName", catchError); atleast in my case it is when looking for what went wrong, and where its having issues.


    @spudland: i picked up WebOS RoughCuts when Mitch was working on, also a couple books on Javascript itself, but mostly trial and error & a lot of reading on palms website
    Last edited by Phrozen; 09/07/2009 at 09:20 PM. Reason: responding to spudland
  4.    #4  
    When I have the "try" activated, it runs but it doesn't seem to do anything. When I comment out the "try", it crashes inside the setup() and the screen doesn't show any data. I can tell from looking at the log file that it never existed the setup() because I have a console.info("setup exit");

    It's weird that I don't get an error with the "try" but it crashes without it. I'll keep working on it and if I ever figure this out, I'll post it here.
  5.    #5  
    I forgot to mention that the checkboxes are inside lists, and I have a formatter to allow me to change the checkbox from data.

    Code:
    	// setup results list widget
    	this.model = {
    		items: [], listTitle: [$L('Results')]
    	};
    
    	listAttributes = {
    		itemTemplate: 'main/search-result',
    		listTemplate: 'main/result-list',
    		formatters:{myData: this.setMyData.bind(this)}
    	};
    	this.controller.setupWidget('results-list', listAttributes, this.model);
    and the formatter is:
    Code:
    MainAssistant.prototype.setMyData = function(propertyValue, model) {
    	if(model.isHappy === true) {
    		model.value = "ON";
    	}
    	else {
    		model.value = "OFF";
    	}
    }
    After an AJAX call, I get the results and turn on/off the checkmarks according to the data from the server:

    Code:
    this.newmodel = {items:[]};
    var oneline = {isHappy: checkmark, recnum: (i+1), myString: vname};
    this.newmodel.items.push(oneline);
    this.model.items = this.newmodel.items;
    this.controller.modelChanged(this.model);
    Everything updates fine but now I need to be able to click on the checkbox and have a callbackfunction executed and I can't seem to get that part of the code to work.

    I'm going to go back to basics and create a sample program without AJAX to see if I can get the checkbox to work by itself, from within a list.
  6. DrewPre's Avatar
    Posts
    818 Posts
    Global Posts
    829 Global Posts
    #6  
    I'm working with something similar to this and I can't seem to assign a label to a check box.... the checkbox itself shows up, but not the label I assigned to it and I can't find documentation that instructs on the correct way to assign a label to a check box.

    Here is my main-assistant.jsjsjs
    Code:
    MainAssistant.prototype.setup = function() {
    	// Set up Call Log Check Box Widget
    	this.checkbox = { property:"value"};
    	this.checkboxModel = { value: true, label:"Call Logs..."};
    	this.controller.setupWidget('CalllogCB', this.checkbox, this.checkboxModel);
    	
    	this.controller.listen('CalllogCB', Mojo.Event.propertyChange, this.changed.bind(this));
    The Div line in main-scene.html reads as follows...
    Code:
    <div x-mojo-element="CheckBox" id="CalllogCB" name="CallLog">Call Logs...</div>
    The checkbox shows up checked but blank...there is no text next to it saying 'Call Logs...'
  7. #7  
    I'm not a javascript expert, so I'm not 100% sure about this, but it seems like this line code would be suspicious:

    Code:
    this.checkboxCallback = this.checkboxCallback.bindAsEventListener(this);
    Can you set a function object to itself? How about trying something like this:

    Code:
    this.checkboxCallbackBinded = this.checkboxCallback.bindAsEventListener(this);
    Mojo.Event.listen(this.checkbox, Mojo.Event.propertyChange, this.checkboxCallbackBinded);
  8. #8  
    Quote Originally Posted by DrewPre View Post
    I'm working with something similar to this and I can't seem to assign a label to a check box.... the checkbox itself shows up, but not the label I assigned to it and I can't find documentation that instructs on the correct way to assign a label to a check box.

    Here is my main-assistant.jsjsjs
    Code:
    MainAssistant.prototype.setup = function() {
    	// Set up Call Log Check Box Widget
    	this.checkbox = { property:"value"};
    	this.checkboxModel = { value: true, label:"Call Logs..."};
    	this.controller.setupWidget('CalllogCB', this.checkbox, this.checkboxModel);
    	
    	this.controller.listen('CalllogCB', Mojo.Event.propertyChange, this.changed.bind(this));
    The Div line in main-scene.html reads as follows...
    Code:
    <div x-mojo-element="CheckBox" id="CalllogCB" name="CallLog">Call Logs...</div>
    The checkbox shows up checked but blank...there is no text next to it saying 'Call Logs...'
    I couldn't find anything on the Palm Dev site to indicate "label" was an available model parameter. But assuming it is, perhaps it's not showing up because you don't have your CSS class defined in the HTML code such as:

    class="checkboxClass"

    It's possible that this CSS class is what sets up the widget's sub-components (label, checkbox, etc.). This is purely a guess though.
  9. DrewPre's Avatar
    Posts
    818 Posts
    Global Posts
    829 Global Posts
    #9  
    I was afraid of that. I am really confused when it comes to setting up CSS files.

    I assume I would add a class statement to my checkbox DIV tag and then have that statemen reference the checkboxClass section of the CSS file, but what would I put in that section of the file?
  10. #10  
    EDIT: I saw in another thread someone mentioned that the "label" property does not exist for checkboxes, which is what I suspected initially after viewing the Palm Dev site. So I think that's your issue.
    Last edited by DanPLC; 10/30/2009 at 09:05 AM.
  11. DrewPre's Avatar
    Posts
    818 Posts
    Global Posts
    829 Global Posts
    #11  
    Hmmmm, I would love to read that thread.

    I have to say... I have some html experience and some jscript experience, but mostly with just tweaking other peoples code that I come across when needed.

    I have never written anything from scratch like I am attempting to do now.

    Having said that, I have played around with the code that I have above, I was able to get a label on the checkbox, but if memory serves me correctly it went away when I tried to add a listener!

    I am not able to reproduce that though.

    I must have tried about a half dozen different code snippets to produce this simple little checkbox and one of them allowed the "Call Logs..." Label to display next to the checkbox.

    Again, that was until I added the listener. At least that's what I think disabled it.

    It's unfortunate that there is very little documentation and/or examples on this widget.
  12. DrewPre's Avatar
    Posts
    818 Posts
    Global Posts
    829 Global Posts
    #12  
    HEH!

    You know when you've been banging your head against a monitor all night and trying to get that square peg into the round hole and you WILL NOT give in to inanimate objects because they are NOT smarter than you....It's sometimes better to just let go, go to sleep, get something to eat, go have a smoke, take a break....

    ...then come back and attempt a resolution.

    Apparently the LABEL for checkbox does not go inside of the DIV tag specifying the checkbox, it goes outside and directly AFTER the DIV tag specifying the checkbox in the main-scene.html file.

    like so....
    Code:
    <div x-mojo-element="CheckBox" id="CalllogCB" name="CallLog"></div>Call Logs...
    This is not what I did before and somehow I saw a label appear next to the checkbox just like I wanted it. I swear! I seened it!!! But this worx!! I will take it, especially since I can reproduce it consistently and whatever I did before I can't seem to reproduce!

Tags for this Thread

Posting Permissions