How can I recover the value of a variable sent per myVar date and use in the checkbox?

Asked

Viewed 63 times

0

index.blade.php
<table>
    @foreach($masters as $master)
        <tr>
            <td>{{$master->receive_email_neworder_masters}}</td>
            <td>
                <button
                    class="btn btn-info"
                    data-my_table = "masters"
                    data-myVar = "{{$master->receive_email_neworder_masters}}"
                    data-toggle="modal"
                    data-target="#edit">Edit
                </button>
            </td>
        </tr>
    @endforeach
</table>
<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="box box-primary box-header with-border">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">Edit </h4>
                </div>
                <form action="{{route('masters.update', 'test')}}" method="post">
                    {{method_field('patch')}}
                    {{csrf_field()}}
                    <div class="modal-body">
                        @include('masters.form_edit')
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary">Save</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
$('#edit').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget); {
    var myVar = button.data('myVar');
    var modal = $(this);
    modal.find('.modal-body #strVar').val(myVar);
    }
}
</script>

form.blade.php    
<div class="input-group">
    <input name="checkbox"
        id="idvar"
        type="checkbox"
        checked="strVar"> <!-- Quero usar aqui -->
    <label>
        I will desire receive email when insert new order.
    </label>
    <br />
</div>

Inside the checkbox I want to check according to the value of myVar (Yes or No), the value that is in the field and already confirmed via Alert(strVar) is set to No but is working inside the checkbox. The foreach makes a list and for each record I select a variable and put inside the button, then in the script I take the value and Seto for a variable that will be used inside a modal with a form. Everything works well for other purposes, but within the checkbox I can not make work and do not know access to variable.

Simply put, it would be something to work with:

'id_buildings é uma variavel setada dentro do script e funciona bem aqui no input'
<label>Buindings</label>
<input type="text" class="form-control" name="id_buildings" readonly="readonly" id="id_buildings">

<script>
    $('#edit').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var id_buildings = button.data('my_id_buildings');
        var modal = $(this);
        modal.find('.modal-body #id_buildings').val(id_buildings);
        modal.find('  ').val(id_buildings);
    }
</script>

'id_building não funciona aqui porque ela não é um tipo php'
{!! Form::select('id_buildings', $buildings, null ) !!

Thank you guys for any kind of help!

  • 1

    Try to explain your doubt better, keep in mind that we do not know how its interface, or anything else.

  • Yes, I’ll change the question! Thank you!

1 answer

1

Simple, I don’t know if it’s the best mode, but it’s the fastest, creates a $_SESSION[] plays the value in recovers where you want and destroys the session

Updating With the amount already recovered within the session you will do the following. Let’s assume you created the sessao ex value $_SESSION['value']; in chekbox you will do it


inesplicavel as I can not put the codes here in this stack in Portuguese is impressive, but does the following paste the code in Pastebin

https://pastebin.com/3NtUpYiJ

  • If I’m going to use this feature as the ultimate resource, could you tell me what it would look like inside the checkbox? A simple example? Thank you very much!

  • 1

    I updated the answer, I made an example in practice for you, only you implement in your code

  • Thanks again, I copied the code, I’ll test.

  • quiet, after testing comments here if it worked.

  • So... @Martins Luan the proposal is to recover the value of the variable with the button values and through javascript pass to the checkbox, I do not have access to the variable via PHP, so there is no way to apply this way as you mentioned. Thanks for now.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.