'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?

Comments

  • edited 5:32AM
    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 5:32AM
    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 5:32AM
    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 (http://docs.getfuelcms.com/general/javascript#modules).
  • edited 5:32AM
    That looks to be a bug... I'm looking into it.
  • edited 5:32AM
    A fix for this should be in the development branch.
Sign In or Register to comment.