Written by

Alenia B.V.
Question Marco Blom · 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!

Comments

Vitaliy Serdtsev · Jul 7, 2017

By the way: some server side alternative solution sample(s) are more than welcome!
$zcvt
USER>w $zcvt("BLACKFIN CAPITAL PARTNERS","W")
Blackfin Capital Partners
USER>w $zcvt("MARK'S 'MARK'S (MARK'S)","W")
Mark's 'Mark's (Mark's)

0
Vitaliy Serdtsev · Jul 7, 2017

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 } }

0
Marco Blom  Jul 8, 2017 to Vitaliy Serdtsev

Hi Vitaliy,

Thanks for you're response and code sample!

However I still have the behavior.

Could I be the issue that I am using a datacontroller / datamodel?

I am interested in the solution for reason that I do use a lot of similar forms.

see code:

Could the issue be something with the dataBinding?

Sorry I do not know how to present the sample code as you do!

0
Vitaliy Serdtsev  Jul 10, 2017 to Marco Blom

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(" ");
}
}
0
Marco Blom  Jul 12, 2017 to Vitaliy Serdtsev

Thank you Vitaliy, it works, I do now see what I have missed.

0