Quantcast
Viewing all articles
Browse latest Browse all 293522

form #states not working with literal integers as values in IE8

To reproduce, say you have a form like this one:

<?php
   
// switching to 'bar' item should display 'dependant' text field
   
$form['principal'] = array(
       
'#type'=> 'radios',
       
'#title'=> 'Principal',
       
'#options'=> array('foo', 'bar'),
       
'#default_value'=> 0,
    );

   
// should get displayed based on selection on 'principal'
   
$form['dependant'] = array(
       
'#type'=> 'textfield',
       
'#title'=> 'Dependant',
       
'#states'=> array(
           
'visible'=> array(
               
// (1) works with this, because a explicit string "1" is passed: ':input[name="principal"]' => array('value' => "1"),
               
':input[name="principal"]'=> array('value'=> 1), // doesn't work in IE8
           
),
        ),
    );
?>

Switching 'principal' radio buttons it is expected that 'dependant' text field is displayed and hidden.

Instead, in IE8 (without uncommenting section (1)), 'dependant' visible state is never changed on 'principal' changes, the problem is because of the usage of 'reference.constructor.name' js which is not supported on IE8 and the posterior call to

function compare (a, b) {
  return (a === b) ? (typeof a === 'undefined' ? a : true) : (typeof a === 'undefined' || typeof b === 'undefined');
}

Where this method compares considering types (and the actual values compared are a Number vs a String, which gets false).

I'm attaching a module to reproduce this issue easily and a patch tested on Firefox, Chome and IE8.

Notes:

Bug only found in IE8, problem could exist in newer IE versions.

AttachmentSizeStatusTest resultOperations
form_states_not_working_with_literal_integers_as_values_in_IE8.patch1.04 KBIgnored: Check issue status.NoneNone
fix_problem_with_states_js.zip1.37 KBIgnored: Check issue status.NoneNone

Viewing all articles
Browse latest Browse all 293522

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>