laravel - pass a datum between tabs

1

It must be something simple, but I've only been with Laravel for two weeks now and there are many things that I do not know and this is one of them.

In tab1 I have a cell that is capital that I enter a value and I would like it when I click on the second tabs. show me another cell with the value I put in capital + 1000.

    <!-- Tab panes -->
    <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="tab1">
                {!! Form::label('capital', 'Cantidad') !!}
                {!! Form::text('capital', null, ['class' => 'form-control', 'placeholder' => 'Ingrese Cantidad $$$' , 'required']) !!}
                </div>
</div>
        <div role="tabpanel" class="tab-pane" id="tab2">
<!-- Que Muestre lo que escribi en tab1=capital + $1000  -->

</div>
    </div>
</div>
<!-- Tab fin -->

This is my complete code

@extends('layouts.app')
@section('title', 'Cantidades')
@section ('content')

<!-- Nav tabs -->
<div role="tabpanel">
<ul class="nav nav-tabs" role="tablist">
    <li role="presentation" class="active"><a href="#tab1" aria-controls="tab1" role="tab" data-toggle="tab">Tab 1</a></li>
    <li role="presentation"><a href="#tab2" aria-controls="tab2" role="tab" data-toggle="tab">Tab 2</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="tab1">
    {!! Form::label('capital', 'Cantidad') !!}
    {!! Form::text('capital', null, ['class' => 'form-control', 'placeholder' => 'Ingrese Cantidad $$$' , 'required']) !!}
</div>
<div role="tabpanel" class="tab-pane" id="tab2">
    {!! Form::text('capital2', null, ['class' => 'form-control' , 'required']) !!}
</div>
</div>

<script>
// detectamos el cambio de valor en el campo capital
$('#capital').on('input', function(){

// comprobamos que sea un entero y en caso contrario, pasamos un cero
var capitalValue = !isNaN(parseInt($(this).val())) ? parseInt($(this).val()) : 0 ;

// sumamos 1000 al valor obtenido de capital y lo ponemos en capital2
$('#capital2').val(capitalValue + 1000);

});
</script>
@endsection

and this is my layouts.app

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>@yield('title','default') | Prestamista</title>
<link rel="stylesheet" href="{{ asset('pluggins/bootstrap/css/bootstrap.css')}}">

<!-- Fonts -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css" integrity="sha384-XdYbMnZ/QjLh6iI4ogqCTaIjrFk87ip+ekIjefZch0Y+PvJ8CDYtEs1ipDmPorQ+" crossorigin="anonymous">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700">

<!-- Styles -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
{{-- <link href="{{ elixir('css/app.css') }}" rel="stylesheet"> --}}

<style>
    body {
        font-family: 'Lato';
    }

    .fa-btn {
        margin-right: 6px;
    }
</style>
</head>
<body id="app-layout">
<nav class="navbar navbar-default navbar-static-top">
    <div class="container">
        <div class="navbar-header">

            <!-- Collapsed Hamburger -->
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-navbar-collapse">
                <span class="sr-only">Toggle Navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>

            <!-- Branding Image -->
            <a class="navbar-brand" href="{{ url('/') }}">
                Prestamista
            </a>
        </div>

        <div class="collapse navbar-collapse" id="app-navbar-collapse">
            <!-- Left Side Of Navbar -->
            <ul class="nav navbar-nav">
                <li><a href="{{ url('/home') }}">Inicio</a></li>
            </ul>
    @if(Auth::user())
                <ul class="nav navbar-nav">
                <li><a href="{{ url('/clients') }}">Clientes</a></li>
            </ul>
                <ul class="nav navbar-nav">
                <li><a href="{{ url('/loans') }}">Prestamos</a></li>
            </ul>
    @if((Auth::user()->tipo)==='admin')
            <ul class="nav navbar-nav">
                <li><a href="{{ url('/users') }}">[Usuarios]</a></li>
            </ul>
    @endif
    @else 
    @endif

            <!-- Right Side Of Navbar -->
            <ul class="nav navbar-nav navbar-right">
                <!-- Authentication Links -->
                @if (Auth::guest())
                    <li><a href="{{ url('/login') }}">Login</a></li>
                @else
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
                            {{ Auth::user()->name }} <span class="caret"></span>
                        </a>

                        <ul class="dropdown-menu" role="menu">
                            <li><a href="{{ url('/logout') }}"><i class="fa fa-btn fa-sign-out"></i>Salir</a></li>
                        </ul>
                    </li>
                @endif
            </ul>
        </div>
    </div>
</nav>

@yield('content')

<!-- JavaScripts -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js" integrity="sha384-I6F5OKECLVtK/BL+8iSLDEHowSAfUo76ZL9+kGAgTRdiByINKJaqTPH/QVNS1VDb" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
{{-- <script src="{{ elixir('js/app.js') }}"></script> --}}

    
asked by Luis Cárdenas 09.08.2016 в 23:54
source

2 answers

0

Well, it really does not have much to do with Laravel, it's more of a frontend issue, I assume that when you talk about a cell you mean a <input type="text"> of what I see in your code, we're going to make a quick solution with jQuery, although if you do not use it, you can opt for one in pure javascript:

<!-- Tab panes -->
<div class="tab-content">
    <div role="tabpanel" class="tab-pane active" id="tab1">
        {!! Form::label('capital', 'Cantidad') !!}
        {!! Form::text('capital', null, ['class' => 'form-control', 'placeholder' => 'Ingrese Cantidad $$$' , 'required']) !!}
    </div>
    <div role="tabpanel" class="tab-pane" id="tab2">
        {!! Form::text('capital2', null, ['class' => 'form-control' , 'required']) !!}
    </div>
</div>

<script>
  // detectamos el cambio de valor en el campo capital
  $('#capital').on('input', function(){

    // comprobamos que sea un entero y en caso contrario, pasamos un cero
    var capitalValue = !isNaN(parseInt($(this).val())) ? parseInt($(this).val()) : 0 ;

    // sumamos 1000 al valor obtenido de capital y lo ponemos en capital2
    $('#capital2').val(capitalValue + 1000);

  });
</script>
    
answered by 10.08.2016 / 00:49
source
0

If the error I had was that I had to specify the id, I thought that only with "text ('capital2')" I already identified it. and no ... I had to put the "'id' = & 'capital2'" and everything worked fine. thanks for the script Shaz !!

{!! Form::text('capital2', null, ['class' => 'form-control', 'id' => 'capital2' , 'required']) !!}
    
answered by 11.08.2016 в 22:54