3.2.0

Updating data model question

Below is a template i wrote to allow only numeric input
When I used this template with a javascript array as the data model everything worked fine

However when used with xml I am unable to update the table model the error is on the line marked (1)

I am not very proficient with java script and any help is greatly appreciated.

Thank you

if (!window.Prima) Prima=[]; 
if (!Prima.Templates) Prima.Templates=[]; 

Prima.Templates.NumberInput = Active.Templates.Text.subclass(); 

Prima.Templates.NumberInput.create = function() 
{ 
    var obj = this.prototype; 

    // editor is not part of the template, 
    // there is only one single instance of editor object. 
    var editor = new Active.HTML.INPUT; 
    editor.setClass("templates", "input"); 
    editor.setAttribute("type", "text"); 
    editor.setAttribute("value", function()
    {
        return template.getItemProperty("text"); 
    }); 

    // template variable provides temporary reference 
    // to the parent template during edit mode. 
    var template; 

    function switchToEditMode()
    { 
        template = this; 
        template.element().style.padding = 0; 
        template.element().innerHTML = editor; 
        editor.element().focus(); 
    } 

    obj.setEvent("ondblclick", switchToEditMode); 

    function switchToTextMode()
    { 
        var value = editor.element().value; 
        var intVal = value * 1;

        if(!isNaN(intVal))
        {
            //alert(intVal);
            template.setItemProperty("text", value);  ---- (1)
        }
        template.refresh(); 
        template = null; 
    } 

    editor.setEvent("onblur", switchToTextMode); 
}; 

Prima.Templates.NumberInput.create();
Bhaskar
July 23,

Buddy, What are you upto?

To my knowledge, Active.XML.Table is read only.

table.js line# 176
obj.getText = function(i, j){
        var node = this.getNode(i, j);
        var data = node ? node.text : "";
        var format = this._formats[j];
        return format ? format.dataToText(data) : data;
    };


And I don't see any setText method (bump...)

Sudhaker Raj
July 24,
Exactly I tried it with array and would also like to try it with xml and was asking how this could be done.

Thanks
Bhaskar
July 25,
Hi,

I just realized that may be I could rephraze my question.

I would like to edit the grid which is possible using the editor described above. I do not really require to update the data model as long as I can update the grid to display the new value.

Once again thank you for your response
Bhaskar
July 25,

I guess, in your code at (1)

template.setItemProperty("value", value);


will do the trick, but grid.refresh() will loose the new value.
Sudhaker Raj
July 25,
I tried that and I could not get it to work.
Alex, I think I saw a message where you had written some code for manipulating the xml. I am however unable to locate that code in the forum at this time. Can you please provide the link or code here

Thanks
Bhaskar
July 26,
Hey I think I found it

http://www.activewidgets.com/messages/1621-0.htm
Bhaskar
July 26,
Yes, this is it. You have to implement setText method on the XML data model.
Alex (ActiveWidgets)
July 26,

This topic is archived.

See also:


Back to support forum