Developer forum

Forum » Development » Implement a custom order line field as a checkbox

Implement a custom order line field as a checkbox


Reply

Hi there,
 
I am trying to implement a custom order line field as a checkbox. I added the following code to my product template
 
<!--@If(Ecom:Product.OrderLineField.SystemName=='PrintBold')--> <input
id="Checkbox1" type="checkbox"
name="<!--@Ecom:Product.OrderLineField.InputTextFieldName-->" /> <!--@EndIf-->
<!--@If Not(Ecom:Product.OrderLineField.SystemName=='PrintBold')-->
<!--@Ecom:Product.OrderLineField.InputTextField--><br /> <!--@EndIf-->

This works great and assigns the value 'on' to the field when the user checks the checkbox.
 
I use similar code in my Cart template to let a user update the field, but I run into problems when the user unchecks the checkbox at some stage. Here's the flow where it goes wrong:
 
 1. User views product, checks the checkbox and clicks Add to cart.
 2. User views the cart. Using If Statements with contains / startswith I can preselect the checkbox just fine.
 3. User clears the checkbox and clicks next to go to the Information step
 4. User clicks back to view the cart again. The checkbox is now checked again.
 
Between step 3 and 4, Dynamicweb doesn't successfully update the custom order line field. I guess it loops through the Request.Form collection looking for fields that start with OrderLineFieldValue and then find the associated order line field, rather than looping through the available order line fields and trying to find the associated form field values.
Since a checkbox doesn't submit itself when it's unchecked, Dynamicweb doesn't see this field and doesn't update the order line field to an empty string.
 
Could / should this be fixed? I am currently working around it by adding an additional hidden field with the same name. This field is always empty, but at least gets submitted to the server. This works, but leads to an additional comma in the field’s value (e.g. 'on,' instead of 'on').

Any suggestions for a better solution?

Imar
 


Replies

 
Reply
Hi Imar!
The situation is seems like a bug, but it is appears only when using the checkboxes in order line fields such way. I think we will fix this.
Your workaround is really good. Additional  comma you can eliminate by a such modification of template:

      <!--@If(Ecom:Order:OrderLine.OrderLineField.SystemName=='vasOLFCheck')-->
       <input type="checkbox" <!--@Ecom:Order:OrderLine.OrderLineField.Value--> onclick="myOLFCheck(this,'<!--@Ecom:Order:OrderLine.OrderLineField.InputTextField.Name-->')" />
       <input name="<!--@Ecom:Order:OrderLine.OrderLineField.InputTextField.Name-->" id="<!--@Ecom:Order:OrderLine.OrderLineField.InputTextField.Name-->" type="hidden" value="<!--@Ecom:Order:OrderLine.OrderLineField.Value-->" /> 
      <!--@EndIf-->
      <!--@If Not(Ecom:Order:OrderLine.OrderLineField.SystemName=='vasOLFCheck')-->
       <input name="<!--@Ecom:Order:OrderLine.OrderLineField.InputTextField.Name-->" id="<!--@Ecom:Order:OrderLine.OrderLineField.InputTextField.Name-->" maxlength="" type="text" value="<!--@Ecom:Order:OrderLine.OrderLineField.Value-->" />
      <!--@EndIf-->


    function myOLFCheck(myCheckBox, myTxtId){
  var myTxt = document.getElementById(myTxtId);
  if (myTxt){
   if (myCheckBox.checked)
    myTxt.value = 'checked';
   else
    myTxt.value = '';
  }
 }


Best regards, Vladimir.

 
Reply
Right; thanks for that, very useful.

Hope this gets fixed though as it enables you to write much cleaner templates.

Kind regards,

Imar

 

You must be logged in to post in the forum