Announcement

Collapse
No announcement yet.

Custom Fields

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Custom Fields

    I have a customer field on the OCST page and it works fine but I want it to be required and turn red if it is blank when the customer hits the continue button. This is what I have to far.

    <mvt:if expr="NOT g.YearMakeModei_Invalid">
    <font color="red">
    <b>Year, Make and Model of your bike:</b>
    </font>
    <mvt:else>
    <b>Year, Make and Model of your bike:</b>
    </mvt:if>
    <input type="text" name="YearMakeModel" value= "" />

    So when the page loads the text is red right now and I want it to be black until the customer hits the continue button to go to the next page. Since the page first loads with no text it shows red. And I don't want it to test for the expression until the customer hits the continue button. We are on the old MMUI system with this and I tried using code from my dev site but it didn't work.

    #2
    Re: Custom Fields

    Toolbelt and Toolkit have a way to tie into Miva's default validation.

    The way you are doing it now won't work, because even if it is blank, Miva's validation for the form will ignore it.

    You're better off validating that field using JavaScript before the form is submitted.
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Re: Custom Fields

      Here's a little page that does what you want I think. It executes the edit when the page is submitted using the onsubmit in the <form tag:
      <!DOCTYPE html>
      <html>
      <head>
      <title></title>
      <script type="text/javascript">
      function trimString(val) {
      var valu = val;
      valu = rtrimString(valu); //trim trailing spaces
      valu = ltrimString(valu); //trim leading spaces
      return valu; //return trimed variable
      }
      function rtrimString(val) //remove trailing spaces
      {
      var valu = val;
      while (valu.charAt(valu.length - 1) == " ") //trim all trailing spaces
      {
      valu = valu.substr(0,valu.length - 1);
      }
      return valu;
      }
      function ltrimString(val) //remove leading spaces
      {
      var valu = val;
      while (valu.charAt(0) == " ") //trim all leading spaces
      {
      valu = valu.substr(1);
      }
      return valu;
      }


      function edit_bike(obj) {
      var bike = trimString(obj.bike_field.value);
      if (bike == "") {
      obj.bike_field.style.background="red";
      obj.bike_field.focus();
      alert("please enter a value");
      return false;
      }
      alert("OK");
      return true;
      }
      </script>
      </head>
      <body>
      <form action="" onsubmit="return edit_bike(this)">
      <input type="text" name="bike_field" />
      <input type="submit" value="continue" >
      </form>
      </body>
      </html>
      Last edited by wajake41; 08-03-15, 09:06 PM.
      Larry
      Luce Kanun Web Design
      www.facebook.com/wajake41
      www.plus.google.com/116415026668025242914/posts?hl=en


      Comment


        #4
        Re: Custom Fields

        You could always do the following:
        Code:
        <mvt:if expr="s.request_method EQ 'POST' AND ISNULL g.YearMakeModel">
                  <mvt:assign name="g.YearMakeModel_Invalid" VALUE = "'1'" />
        <mvt:else>
                   <mvt:assign name="g.YearMakeModel_Invalid" VALUE = "'0'" />
        </mvt:if>
        or if you understand the logic clearly you could do

        Code:
        
        <mvt:assign name="g.YearMakeModel_Invalid" VALUE = "s.request_method EQ 'POST' AND ISNULL g.YearMakeModel" />
        That should work as desired.
        Last edited by dcarver; 08-04-15, 10:08 AM.
        David Carver
        Miva, Inc. | Software Developer

        Comment

        Working...
        X