Question
· Jul 7, 2017

changed data in field ignored when saving changes

HI Community,

I do have a table with quite some names written in Uppercase:

To simply correct this, I have created a button with some code behind it.:

ClientMethod convertToTitle() [ Language = javascript ]
{
    
    var ctrl zen('Relation');
tVar ctrl.getValue();
     
tVar this.StringConvert(tVar)

    zenPage.getComponentById('Relation').setValue(tVar)
}



ClientMethod StringConvert(str) [ Language = javascript ]
{
    ///alert (str)
    str str.substring(0,1).toLowerCase() tVar.substring(1).toLowerCase();
    ///alert (str)
    var pieces str.split(" ");
    for ( var i 0; i pieces.length; i++ )
    {
        var j pieces[i].charAt(0).toUpperCase();
        
        pieces[i] j pieces[i].substr(1);
    }
        
    return pieces.join(" ");
} ClientMethod convertToTitle() [ Language = javascript ]
{
    
    var ctrl zen('Relation');
tVar ctrl.getValue();
     
tVar this.StringConvert(tVar)

    zenPage.getComponentById('Relation').setValue(tVar)
}



ClientMethod StringConvert(str) [ Language = javascript ]
{
    ///alert (str)
    str str.substring(0,1).toLowerCase() tVar.substring(1).toLowerCase();
    ///alert (str)
    var pieces str.split(" ");
    for ( var i 0; i pieces.length; i++ )
    {
        var j pieces[i].charAt(0).toUpperCase();
        
        pieces[i] j pieces[i].substr(1);
    }
        
    return pieces.join(" ");
}

At first place it seems to worksmiley: using the correct button results in:

 

 

However when I do save (by the button or code), then the data gets replaced with the original Uppercase data.crying

 

Does somebody have a clue why this behavior appears?

Thanks in advance!

By the way: some server side alternative solution sample(s) are more than welcome!

Discussion (5)0
Log in or sign up to continue

At me converted string is stored correctly.

Here is a small example:

Class demo.test Extends %ZEN.Component.page
{

XData Contents [ XMLNamespace "http://www.intersystems.com/zen" ]
{
<page xmlns="http://www.intersystems.com/zen" title="">
  <form
    id="MyForm"
    OnLoadForm="LoadForm"
    OnSubmitForm="SubmitForm"
  >
    <text
      id="Relation"
      name="Relation"
      label="Relation"
      size="50"
    />
    <button caption="1.Convert" onclick="zenPage.convertToTitle();"/>
    <submit caption="2.Save" action="save"/>
  </form>
</page>
}

ClientMethod convertToTitle() [ Language = javascript ]
{
  var ctrl zen('Relation');
  ctrl.setValue(this.stringConvert(ctrl.getValue()));
}

ClientMethod stringConvert(str) [ Language = javascript ]
{
  ///alert (str)
  str str.substring(0,1).toLowerCase() str.substring(1).toLowerCase();
  ///alert (str)
  var pieces str.split(" ");
  for var = 0; i pieces.length; i++ )
  {
    var pieces[i].charAt(0).toUpperCase();
    
    pieces[i] pieces[i].substr(1);
  }
      
  return pieces.join(" ");
}

/// Callback to get values for form
Method LoadForm(
  pKey As %String,
  ByRef pValues As %StringAs %Status
{
  pValues("Relation") = $g(^tmp,"BLACKFIN CAPITAL PARTNERS")
  q $$$OK
}

/// Callback to process values submitted for form.
ClassMethod SubmitForm(pSubmit As %ZEN.SubmitAs %Status
{
  ^tmp
  s:pSubmit.%Action="save" ^tmp=pSubmit.%GetValue("Relation")
  q $$$OK
}
}

Could the issue be something with the dataBinding?

Most likely - yes, see <dataController> Methods.
Simple example:

Class demo.relationModel Extends %ZEN.DataModel.ObjectDataModel
{

Property Relation As %String(MAXLEN 36);

Method %OnLoadModel(pSource As %RegisteredObjectAs %Status
{
  ..Relation $g(^tmp,"BLACKFIN CAPITAL PARTNERS")
  q $$$OK
}

Method %OnStoreModel(pSource As %RegisteredObjectAs %Status
{
  ^tmp
  ^tmp=..Relation
  q $$$OK
}
}

Class demo.test Extends %ZEN.Component.page
{

XData Contents [ XMLNamespace "http://www.intersystems.com/zen" ]
{
<page xmlns="http://www.intersystems.com/zen" title="">
  <dataController
    id="relationData"
    modelClass="demo.relationModel"
  />
  <form
    id="MyForm"
    controllerId="relationData"
  >
    <text
      id="Relation"
      label="Relation"
      name="Relation"
      dataBinding="Relation"
      size="36"
    />
    <button caption="1. Convert" onclick="zenPage.convertToTitle();"/>
    <button caption="2. Save" onclick="zen('MyForm').save();" />
  </form>
</page>
}

ClientMethod convertToTitle() [ Language = javascript ]
{
  var controller zen('relationData');
  
  controller.setDataByName('Relation',this.stringConvert(zen('Relation').getValue()));
  controller.raiseDataChange();
}

ClientMethod stringConvert(str) [ Language = javascript ]
{
  ///alert (str)
  str str.substring(0,1).toLowerCase() str.substring(1).toLowerCase();
  ///alert (str)
  var pieces str.split(" ");
  for var = 0; i pieces.length; i++ )
  {
    var pieces[i].charAt(0).toUpperCase();
    
    pieces[i] pieces[i].substr(1);
  }
      
  return pieces.join(" ");
}
}