Mascara in Laravel form field

Asked

Viewed 1,617 times

0

Good night, all right?

I can’t find a way to include a validation mask with Laravel’s Form Collective. Below the code snippet with a field:

 {{Form::label('comp_nota','Competência')}}
{{Form::text('comp_nota','',['class'=>'form-control','required','placeholder'=>'Ex: 08/2018'])}}

I need that when entering the competence the field add to / in the middle of the field. ex: 02/2018.

That is, the user only type 022018.

What can I wear?

  • {{Form::text('comp_nota','',['class'=>'form-control','required','placeholder'=>'Ex: 08/2018', Pattern="[A-Z]{3}[0-9]{4}"])}}

3 answers

1

Solution:

One way to solve is to use the library jquery.Mask for the masks of your fields.

Example of use:

jQuery(function ($) {
    $("#comp_nota").mask("99/9999");
});

0

Problem

Create field with input type date with laravelcollective/html

Solution

{{Form::label('comp_nota','Competência')}}
{{Form::date('comp_nota','',['class'=>'form-control','required','placeholder'=>'Ex: 08/2018'])}}

Notes

Evaluate the support of this attribute for different browsers https://caniuse.com/#search=input%20date

  • Good evening Jorge, in this case it is in the format dd/mm/yyyy, I needed the format mm/yyyyyy

  • I think the best in this case would be to use an inputmask via javascript library

-3

I needed to use this library jQuery-Mask-Plugin in Laravel, share my solution.

<!doctype html>
<head>
</head>
 <!-- resources/views/layouts/app.blade.php -->
<body>
    <div id="app">
        @yield('content')
    </div>

    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
        integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous">
    </script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.js"
        integrity="sha256-yE5LLp5HSQ/z+hJeCqkz9hdjNkk1jaiGG0tDCraumnA=" crossorigin="anonymous"></script>
    
<!-- Carrega o Script Personalizado na Página aqui -->
    @yield("script")

</body>
</html>

Form Cadastrar

 <!-- resources/views/user/create.blade.php -->
@extends('layouts.app')

@section('script')
<script>
    $(document).ready(function($){
        $('#cpf').mask('999.999.999-99');
   });
</script>
@endsection

@section('content')
<form class="form-group" action="{{ action('UserController@store', 0) }}" method="post">
    @csrf
    <div class="col-md-2">
        <label>CPF</label><br>
        <input class="form-control" id="cpf" type="text" name="cpf" required><br>
    </div>
</form>

@stop

Browser other questions tagged

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