Summernote Editor in Laravel Blade Inputs by itself - php

helloo..
i had a quesiton plis..so i have this summer note editor in laravel php blade
<div class="form-group">
<label class="required" for="description">{{ trans('cruds.course.fields.description') }}</label>
<textarea class="form-control {{ $errors->has('description') ? 'is-invalid' : '' }}" name="description" id="summernote"
required>{{ old('description') }}</textarea>
#if ($errors->has('description'))
<div class="invalid-feedback">
{{ $errors->first('description') }}
</div>
#endif
<span class="help-block">{{ trans('cruds.course.fields.description_helper') }}</span>
</div>
and this JS for the summernote script
<script>
$('#summernote').summernote({
placeholder: 'Description...',
tabsize: 2,
height: 100
});
</script>
but the problem is when i am typing in the editor the first two words gets capitilised adn then the cursor move to the starts and write from there as well as stops me from inputting any further after few character are typed..may i know why this is happening as i got the same code in my other php view feature and it works there..
Any help would be appreciated..thanks

Related

Customize Laravel collective form with font awesome

I am looking for a way to add customization to laravel form,instead of using type form
How can I get the following,
<div class="col-sm-4">
<div class="input-group">
<span class="input-group-append">
<span class="input-group-text"><i
class="livicon" data-name="number"
data-size="18" data-c="#000"
data-hc="#000" data-loop="true"></i></span>
</span>
<input type="number" class="form-control"
placeholder="Warehouse No" id="wh_no" name="wh_no" >
</div>
out from laravel forms,this don't load livicion or font-awesome,,ve
{!! Form::number('wh_no', null, ['class' => 'form-control','class'=>'livicon','data-name'=>'user']) !!}
like this

old() value function using data from database not working in Blade

I have a form with 4 input fields, all of them to which I applied an old() function so whenever users load the page after submitting the form, the data that they filled in would retain in the fields for better UX.
My issue is that out of these 4 fields, only 1 has the old() function working. The difference between this field and the others is that:
The name and id attributes for this field are the same, while other fields have different names and IDs respectively.
The input type for this field is type="number" while the other fields are type="text".
Based on these differences, I tried modifying the code to standardize them, and only one solution works which is that I change the input types to "number", however, not all my inputs are numbers, so it is not an ideal solution.
Form blade file:
<div class="form-group mb-3">
<input type="text" class="form-control" name="emp_name" id="company_name"
value="{{ old('emp_name' , (isset($user->emp_detail->emp_name) ? $user->emp_detail->emp_name : old('emp_name')) ) }}">
#if ($errors->has('emp_name'))
<span class="text-danger">{{ $errors->first('emp_name') }}</span>
#endif
</div>
<div class="form-group mb-3">
<input type="number" class="form-control" name="emp_length" id="emp_length"
value="{{ old('emp_length' , (isset($user->emp_detail->emp_length) ? $user->emp_detail->emp_length : old('emp_length')) ) }}">
#if ($errors->has('emp_length'))
<span class="text-danger">{{ $errors->first('emp_length') }}</span>
#endif
</div>
<div class="form-group mb-3">
<input type="text" class="form-control money-prefix" name="emp_monthly_gross_salary" id="monthly_salary"
value="{{ old('emp_monthly_gross_salary' , (isset($user->emp_detail->emp_monthly_gross_salary) ? $user->emp_detail->emp_monthly_gross_salary : old('emp_monthly_gross_salary')) ) }}">
#if ($errors->has('emp_monthly_gross_salary'))
<span class="text-danger">{{ $errors->first('emp_monthly_gross_salary') }}</span>
#endif
</div>
<div class="form-group mb-3">
<input type="text" class="form-control money-prefix" name="monthly_allowance" id="bonus"
value="{{ old('monthly_allowance' , (isset($user->emp_detail->emp_monthly_allowance) ? $user->emp_detail->emp_monthly_allowance : old('monthly_allowance')) ) }}">
#if ($errors->has('monthly_allowance'))
<span class="text-danger">{{ $errors->first('monthly_allowance') }}</span>
#endif
</div>
To be clear, I also have several other forms in which I applied the same old() function, with texts as well as numbers, and they work fine, so I am unsure why the old() function won't work on this form specifically. I also dd() the variables I wanted to output as the old function, so I am sure my controller is already passing the values, my blade just isn't showing it.
Can anyone advise me on this problem?
maybe the issue is the default value, may be set but empty
try to check it with old directly without the default value
ex:
replace
{{ old('emp_name' , (isset($user->emp_detail->emp_name) ? $user->emp_detail->emp_name : old('emp_name')) ) }}
with
{{ old('emp_name') }}
if it works fine with you then you need to enhance the default value condition
ie: (isset($user->emp_detail->emp_name) ? $user->emp_detail->emp_name : old('emp_name')

Resizing bootstrap form box not working when <span> tag is removed

I'm trying to resize a form box using .col-md-12. It works fine if I keep the code inside the span tag as it is, but if I take it off (and I want to, because I need to remove that button) it stops working. In this scenario the form box will maintain some kind of default size, no matter which value is inserted after -md.
Could anyone give some help? If it matters, this HTML file is part of the viewer of a project using laravel framework.
<div class="box-body">
<div class="col-md-12">
<div class="form-group">
<label for="name">{{ 'name' }}</label>
<div class="input-group">
<input class="form-control" type="text" name="name" value="{{ $name }}">
<span class="input-group-btn">
<a class="btn btn-warning" href="{{ url('path', $id) }}" title="{{ 'edit' }}"><i class="fa fa-pencil"></i></a>
</span>
</div>
</div>
</div>
</div>
Provided that I understood your question right, just add the btn class to the span tag and remove the a tag.
<span class="input-group-btn btn">
<!-- removed button -->
</span>

How to edit form with data from database tables in laravel

I am doing project in laravel. I want edit form with database table values.
In controller,
$event_note = DB::table('event_note')->where('event_id',$id)->first();
I have blade.php file for particular textarea as,
<div class="form-group clearfix{{ $errors->has('event_note') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Note</label>
<div class="col-md-6">
<textarea class="form-control" name="event_note" rows="4" cols="50">{{ $event_note->note }}</textarea>
#if ($errors->has('event_note'))
<span class="help-block">
<strong>{{ $errors->first('event_note') }}</strong>
</span>
#endif
</div>
</div>
but as event_note doesn't have any record it throws an error as,
Trying to get property of non-object (View:....
for variable $event_note->note.
I don't know how to edit this form if database table dont have any value it should show an empty textarea.
You can use or '' clause:
{{ $event_note->note or '' }}
It's a Blade shortcut for this solution:
{{ isset($event_note->note) ? $event_note->note : '' }}
"first()" will return "null" if nothing is found in database for this id.
Try this:
<textarea class="form-control" name="event_note" rows="4" cols="50">{{ is_null($event_note) ? null : $event_note->note }}</textarea>

How to Display Validation Errors Next to Each Related Input Field in Laravel 5?

Default solution is trivial:
#if (count($errors) > 0)
<ul id="login-validation-errors" class="validation-errors">
#foreach ($errors->all() as $error)
<li class="validation-error-item">{{ $error }}</li>
#endforeach
</ul>
#endif
and I can include errors.blade.php anywhere.
Is there any way to extract each element and display it next to input field that holds the value that failed?
I assume that would require me to define a lot of conditional if statements next to each input, right?
How to sort this problem? Could you give me any examples?
Thanks.
You can use something like this :
<div class="form-group {{ $errors->has('name') ? 'has-error' : ''}}">
<label for="name" class="col-sm-3 control-label">Name: </label>
<div class="col-sm-6">
<input class="form-control" required="required" name="name" type="text" id="name">
{!! $errors->first('name', '<p class="help-block">:message</p>') !!}
</div>
</div>
#Zorx has given a right solution. But what if there are multiple errors and you want to display all of them at once.
According to the documentation you could use:
Retrieving All Error Messages For A Field
foreach ($errors->get('email') as $message) {
//
}
If you are validating an array form field, you may retrieve all of the messages for each of the array elements using the * character:
foreach ($errors->get('attachments.*') as $message) {
//
}
Retrieving All Error Messages For All Fields
foreach ($errors->all() as $message) {
//
}
Laravel Introduced The #error Directive in version 6 and 7
<input id="title" type="text" name="title" class="#error('title') is-invalid #enderror">
#error('title')
<div class="alert alert-danger">{{ $message }}</div>
#enderror
documentation
Validation individual error message and input border with red color using bootstrap classes and Laravel's $errors directive
Input field with red border color
<input type="text" name="fullName" class="form-control {{($errors->first('fullName') ? 'is-invalid' : '')}}" value="{{old('fullName');}}">
//Or
<input type="text" name="fullName" class="form-control #error('fullName') is-invalid #enderror" value="{{old('fullName');}}">
Individual validation error message
#error('fullName') <div class="alert alert-danger">{{ $message }}</div> #enderror

Categories