Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

'js' parameter in forms not working properly?

edited January 2015 in Bug Reports
In my simple module's form_fields function, if I use this method to include JS:
$fields['my_field'] = array('type' => 'select', 'options' => array(), 'js' => '<script>alert( "hello" );</script>');
the "hello" alert is thrown on page load.

If I use this method:
$fields['my_field'] = array('order' => '-80', 'type' => 'select','options' => array(), 'js' => 'hello');
Nothing happens even though the same "alert( "hello" );" code is used in the hello.js file (which is in "assets/js").

Bug, or am I doing something wrong?


  • edited 11:48AM
    I'm getting the following JS errors in the console (using the second scenario):

    If the js filename matches the field name $fields['my_field'] ... 'js' => 'myfield' I get the following error: "TypeError: my_field is not a function"

    If the js filename id different $fields['my_field'] ... 'js' => 'hello' I get this one: "ReferenceError: hello is not defined"
  • edited 11:48AM
    Try using an array instead of a string if you want to include a javascript file. You can use a string value if you want to put the javascript inline e.g. 'js' => 'hello()'
  • edited 11:48AM
    I get the exact same results when using an array - 'js' => array('hello').

    In the documentation, a string is used both for inlining the code and including a file (
  • edited 11:48AM
    That looks to be a bug... I'm looking into it.
  • edited 11:48AM
    A fix for this should be in the development branch.
Sign In or Register to comment.