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
{

</FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">Relation </FONT><FONT COLOR="#000080">As %String</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#000080">MAXLEN </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#000080">36</FONT><FONT COLOR="#000000">);

</FONT><FONT COLOR="#000080">Method </FONT><FONT COLOR="#000000">%OnLoadModel(</FONT><FONT COLOR="#ff00ff">pSource </FONT><FONT COLOR="#000080">As %RegisteredObject</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#000080">As %Status </FONT><FONT COLOR="#000000">{   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#000000">..</FONT><FONT COLOR="#0000ff">Relation </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#0000ff">$g</FONT><FONT COLOR="#000000">(^tmp,</FONT><FONT COLOR="#008000">"BLACKFIN CAPITAL PARTNERS"</FONT><FONT COLOR="#000000">)   </FONT><FONT COLOR="#0000ff">q $$$OK </FONT><FONT COLOR="#000000">}

</FONT><FONT COLOR="#000080">Method </FONT><FONT COLOR="#000000">%OnStoreModel(</FONT><FONT COLOR="#ff00ff">pSource </FONT><FONT COLOR="#000080">As %RegisteredObject</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#000080">As %Status </FONT><FONT COLOR="#000000">{   </FONT><FONT COLOR="#0000ff">k </FONT><FONT COLOR="#000000">^tmp   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#000000">^tmp=..</FONT><FONT COLOR="#0000ff">Relation   q $$$OK </FONT><FONT COLOR="#000000">} }</FONT>

<FONT COLOR="#000080">Class demo.test Extends %ZEN.Component.page </FONT><FONT COLOR="#000000">{

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

</FONT><FONT COLOR="#000080">ClientMethod </FONT><FONT COLOR="#000000">convertToTitle() [ </FONT><FONT COLOR="#000080">Language </FONT><FONT COLOR="#000000">= javascript ] {   </FONT><FONT COLOR="#008080">var </FONT><FONT COLOR="#000000">controller </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#000000">zen(</FONT><FONT COLOR="#800000">'relationData'</FONT><FONT COLOR="#000000">);      controller.setDataByName(</FONT><FONT COLOR="#800000">'Relation'</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">this</FONT><FONT COLOR="#000000">.stringConvert(zen(</FONT><FONT COLOR="#800000">'Relation'</FONT><FONT COLOR="#000000">).getValue()));   controller.raiseDataChange(); }

</FONT><FONT COLOR="#000080">ClientMethod </FONT><FONT COLOR="#000000">stringConvert(</FONT><FONT COLOR="#ff00ff">str</FONT><FONT COLOR="#000000">) [ </FONT><FONT COLOR="#000080">Language </FONT><FONT COLOR="#000000">= javascript ] {   </FONT><FONT COLOR="#008000">///alert (str)   </FONT><FONT COLOR="#000000">str </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#000000">str.substring(</FONT><FONT COLOR="#000080">0</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#000080">1</FONT><FONT COLOR="#000000">).toLowerCase() </FONT><FONT COLOR="#000080">+ </FONT><FONT COLOR="#000000">str.substring(</FONT><FONT COLOR="#000080">1</FONT><FONT COLOR="#000000">).toLowerCase();   </FONT><FONT COLOR="#008000">///alert (str)   </FONT><FONT COLOR="#008080">var </FONT><FONT COLOR="#000000">pieces </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#000000">str.split(</FONT><FONT COLOR="#800000">" "</FONT><FONT COLOR="#000000">);   </FONT><FONT COLOR="#008000">for </FONT><FONT COLOR="#000000">( </FONT><FONT COLOR="#008000">var </FONT><FONT COLOR="#000000">i </FONT><FONT COLOR="#000080">= 0</FONT><FONT COLOR="#000000">; i </FONT><FONT COLOR="#000080">< </FONT><FONT COLOR="#000000">pieces.length; i</FONT><FONT COLOR="#000080">++ </FONT><FONT COLOR="#000000">)   {     </FONT><FONT COLOR="#008080">var </FONT><FONT COLOR="#000000">j </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#000000">pieces[i].charAt(</FONT><FONT COLOR="#000080">0</FONT><FONT COLOR="#000000">).toUpperCase();          pieces[i] </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#000000">j </FONT><FONT COLOR="#000080">+ </FONT><FONT COLOR="#000000">pieces[i].substr(</FONT><FONT COLOR="#000080">1</FONT><FONT COLOR="#000000">);   }          </FONT><FONT COLOR="#008000">return </FONT><FONT COLOR="#000000">pieces.join(</FONT><FONT COLOR="#800000">" "</FONT><FONT COLOR="#000000">); } }</FONT>

0
Marco Blom  Jul 12, 2017 to Vitaliy Serdtsev

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

0