Announcement

Collapse
No announcement yet.

ATTN all: New customfield checkbox behaviour, review your code! EQ 'yes' and NE 'yes'

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

    ATTN all: New customfield checkbox behaviour, review your code! EQ 'yes' and NE 'yes'

    Originally posted by dcarver View Post
    In 9.07 custom fields checkboxes were changed from 'yes' to '1' since it should be considered a boolean field.

    At the moment all existing (pre 9.07) customfield checkboxes are returning 'yes' until you cahnge their state. After they are re-activated they will return 1. You may have a mixture of 'yes' and 1 for the same product.
    details

    Code:
        <mvt:if expr="g.my_customfield_checkbox_var EQ 'yes'">    <---- WRONG
        <mvt:if expr="g.my_customfield_checkbox_var NE 'yes'">    <---- WRONG
        <mvt:if expr="NOT ISNULL g.my_customfield_checkbox_var">    <---- CORRECT matches yes and 1
        <mvt:if expr="ISNULL g.my_customfield_checkbox_var">    <---- CORRECT matches an empty field or not assigned variable
    Review your code guys or it may stop working as expected one day.

    #2
    I don't think (ISNULL g.xxx) will return 1 if g.xxx contains the empty string. ISNULL only returns 1 if the variable has never been assigned any value. Empty-string is not the same as null. If you set g.xxx to 'something' and then set it to empty-string, it still has a value, and (ISNULL g.xxx) will return false.
    Kent Multer
    Magic Metal Productions
    http://TheMagicM.com
    * Web developer/designer
    * E-commerce and Miva
    * Author, The Official Miva Web Scripting Book -- available on-line:
    http://www.amazon.com/exec/obidos/IS...icmetalproducA

    Comment


      #3
      ISNULL will return 1 if the variable is a string and the string length is 0.
      David Carver
      Miva, Inc. | Software Developer

      Comment


        #4
        Are you positive? I had a problem with a module a while ago, and that turned out to be the cause IIRC.
        Kent Multer
        Magic Metal Productions
        http://TheMagicM.com
        * Web developer/designer
        * E-commerce and Miva
        * Author, The Official Miva Web Scripting Book -- available on-line:
        http://www.amazon.com/exec/obidos/IS...icmetalproducA

        Comment


          #5
          Originally posted by Kent Multer View Post
          Are you positive? I had a problem with a module a while ago, and that turned out to be the cause IIRC.
          I just ran tests to verify it.

          Code:
          <mvt:eval expr="ISNULL g.Test" /><br />
          
          <mvt:assign name="g.Test" value="'123'" />
          <mvt:eval expr="ISNULL g.Test" /><br />
          
          <mvt:assign name="g.Test" value="''" />
          <mvt:eval expr="ISNULL g.Test" /><br />
          gave me this output

          Code:
          1
          0
          1
          David Carver
          Miva, Inc. | Software Developer

          Comment


            #6
            That seems pretty definitive. I'm pretty sure I saw the opposite behavior in my own work. I was writing Miva Script at the time, not template code.

            Thanks --
            Kent Multer
            Magic Metal Productions
            http://TheMagicM.com
            * Web developer/designer
            * E-commerce and Miva
            * Author, The Official Miva Web Scripting Book -- available on-line:
            http://www.amazon.com/exec/obidos/IS...icmetalproducA

            Comment


              #7
              I was under the impression that, depending on the data type of the field, and empty field could still give a positive on 'ISNULL' if the field was not specifically set to be 'null' with no value. For example, a text type field could contain a 'space', which ISNULL would eval to 'true'.
              Bruce Golub
              Phosphor Media - "Your Success is our Business"

              Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
              phosphormedia.com

              Comment


                #8
                But space is not an empty field. Space has a char id.
                My only concern is '0', as Miva guys want to treat checkbox as a boolean field they may decide to return 0 when checkbox is not checked. ISNULL will fail in this case

                Code:
                        <mvt:eval expr="ISNULL g.tst" />
                        <mvt:assign name="g.tst" value="0" />
                        <mvt:eval expr="ISNULL g.tst" />
                        <mvt:assign name="g.tst" value="1" />
                        <mvt:eval expr="ISNULL g.tst" />
                        <mvt:assign name="g.tst" value="'yes'" />
                        <mvt:eval expr="ISNULL g.tst" />
                        <mvt:assign name="g.tst" value="''" />
                        <mvt:eval expr="ISNULL g.tst" />
                
                
                1 0 0 0 1

                Comment


                  #9
                  oh, sorry herb, i was replying to kent's comment.
                  Bruce Golub
                  Phosphor Media - "Your Success is our Business"

                  Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
                  phosphormedia.com

                  Comment

                  Working...
                  X