Blade, javascript and variables

Posted 4 years ago by citrex

Hello !

i've a little problem about passing variables from blade to javascript after using a form component :

@include('my.view', ['field_name' => 'field', 'field_id' => 'field_id' ])

inside my.view :

<div class="form-group">
    {!! Form::label($field_name, $field_label) !!}
    {!! Form::file($field_name, ['id'=> $field_id,'class' => 'form-control']) !!}

    App.initialize(  \{{$field_id \}} ); // (i escape because on Laracasts it disapear )

and in the javascript :

initialize: function (form_element) {

my console.log always return me an instance of [object HTMLInputElement]. my php variable is a string and whatever the name of the variable is, if the content of the variable equals the name or the id of my input, my variable is transformed into [object HTMLInputElement].

i need to know if is a normal behaviour or if some one has a solution !

Thanks you :)

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.