React-bootstrap, not saved changes from Form.Control - react-bootstrap

I have a code:
<Form.Control
type="text"
name="username"
value={Auth.getState.username}
onChange= {(e) => {Auth.handleChange(e)}}
placeholder='Введите Никнейм'/>
And have an error on "onChange= {(e) => {Auth.handleChange(e)}}": '19 stack frames were expanded.'
Please help, what's wrong?
Thank

Sorry, it was an error in function's name. Code 'onChange= {(e) => {Auth.handleChange(e)}}' work properly

Related

image does not want to be updated if the other values are not changed

I want to update the user image but the user image will only be updated if other values are also updated, such as name/username, I have tried various ways, even though in the edit post section there is no problem
so this is my form
<form action="/profile/{{ auth()->user()->id }}" method="post" enctype="multipart/form-data">
#method('put')
#csrf
<label for="">Name</label>
<input type="text" name="name" value="{{ auth()->user()->name }}">
<label for="">Username</label>
<input type="text" name="username" value="{{ auth()->user()->username }}">
<label for="">Profile Picture</label>
<input type="file" name="image">
<button type="submit">Update</button>
</form>
my web route
Route::get('/profile/{user}/edit', [ProfileController::class, 'edit'])->middleware('auth');
my ProfileController
$rules = [
'name' => ['required', 'max:15'],
'username' => ['required', 'min:5', 'max:12', 'unique:users'],
'image' => ['nullable','image','file','max:1024'],
];
$validatedData = $request->validate($rules);
if($request->file('image')) {
if($user->image){
Storage::delete($user->image);
}
$validatedData['image'] = $request->file('image')->store('profile-images');
}
$user->update($validatedData);
return back();
I have tried several ways and I have also created an edit post feature and it works well, I tried to copy and paste the code and change a little from the edit post feature but it doesn't work, the image is only updated if the other values are also edited / updated, what I want is that the image is updated even if the others are not updated, thank you
It seems to be due to the browser cache history.
Browsers usually store image data in cache. So if the image name is the same it won't be updated.
So I solved this problem like this.
All image names contain a unique random string with extension + ?
ex:Lynn.jpg?33f3r3

How can I receive a specific index of an validator array of array validation in Laravel?

I validate an array in laravel controller and receive message by using $errors->first('field_name') or $errors or $errors->has('field_name). Now the problem is, I validate an array named vaccine_certificate and I can not receive the error message. Actually I receive the message when show all erros at once. but I want to show it with it's input area. How can I solve it?
$this->validate($request, [
'name' => 'required',
'employee_no' => 'required',
'vaccine_certificate.*' => 'image|mimes:png,jpg|max:2048|dimensions:max_height=200,max_width=200',
//'expertise' => 'required',
]);
Input field looks like
<div class="col-6 form-group">
<label class="control-label " for="vaccine_certificate"><h5 class="h6">Vaccine Certificate <small>(<2mb,png,jpg) </small> </h5></label>
<input class="form-control" type="file" name="vaccine_certificate[]" id="vaccine_certificate" multiple/>
#if ($errors->has('vaccine_certificate'))
<p id="employee_no_checker_message" class="text-danger p-2" onload="changeInputBorderColor('vaccine_certificate')"> {{ $errors->first('vaccine_certificate') }}</p>
#endif
</div>
You can use and see all errors in the error bag of form.
$errors->all()
However, as far as I can see there is no "required" in vaccine_certificate, and your rule is vaccine_certificate.*, that means it should be an array. If you make it vaccine_certificate and required like you did in the name field you can see the error message.
If you need to use array, you can use:
$errors->first('vaccine_certificate.*')
Since it is not "required" it will not throw an error and you can not see it in the $errors variable.

Laravel - what does this bit of code mean?

<div class ="form-group">
{!! Html::decode(Form::label('first_name','<strong>First Name:</strong>')) !!}
{{Form::text('first_name', old('first_name'), ['class' => 'form-control '.($errors->has('first_name') ? 'is-invalid': ''), 'placeholder' => '', 'required'])}}
</div>
What does this bit of the code mean?
($errors->has('first_name') ? 'is-invalid': '')
"If the first_name field has errors, print is-invalid, otherwise print nothing."
Basically, it's applying the is-invalid class to fields that are invalid (per the Laravel validator). In Bootstrap, this typically turns the field red so the user can see it's incorrect.
That is called a Ternary. Shorthand for if/else
Here is post on those that is helpful:
https://davidwalsh.name/php-shorthand-if-else-ternary-operators

Laravel validation if input is not empty required_with

I'm using laravel and i have a request form with rule like this:
'postal_code1' => 'required',
'postal_code2' => 'required_with:postal_code1|numeric',
and some html
<input type="text" name="postal_code1" />
<input type="text" name="postal_code2" />
The trouble i met that when i don't fill the postal_code1,
I receive the error
Postal_code2 must be a number
How do numeric rule run only if the input is filled?
I tried the sometimes rule:
'postal_code2' =>'sometimes|required_with:postal_code1|numeric'
But not working
I have found the solution, it's very easy. Change the rule as below:
'postal_code2' => 'nullable|required_with:postal_code1|numeric'

Laravel form binding

Hi I am using laravel form binding along with
jqBootstrapValidation . In order to successfuly have the validate the input fields, I must pass something like "required" (without quotes) in the tag . Can you please let me know how can I achieve this ?
FYI .. the minlength works fine but the required does not work.
For example one of input elements currently looks as such
{{Form::text('username', null, array('class'=> 'form-control tip', 'data-toggle'=> 'tooltip', 'data-placement'=> 'bottom', 'title'=>'Enter your username that you have been using till now. This is a compulsory field.','placeholder'=>'Username ( must be filled )','minlength'=>'2'))}}
Thanks
You can't, take a look at the source code that builds the attributes:
protected function attributeElement($key, $value)
{
if (is_numeric($key)) $key = $value;
if ( ! is_null($value)) return $key.'="'.e($value).'"';
}
You'll always get a <attribute>=<name>, what you can test is to use it this way:
{{ Form::text('username',
null,
array( 'class'=> 'form-control tip',
'data-toggle'=> 'tooltip',
'data-placement'=> 'bottom',
'title'=>'Enter your username that you have been using till now. This is a compulsory field.',
'placeholder'=>'Username ( must be filled )',
'minlength'=>'2',
0 => 'required'
)
)
}}
It will build a tag
<... required="required" ...>
And it might work for jqBootstrapValidation.
Otherwise you'll have to create those inputs manually.
I've used this with the HTML attributes required="required" and also required="" works too. Changing the example they provide and adding in the Laravel Blade tags gives
<form class="form-horizontal" novalidate>
<div class="control-group">
<label class="control-label">Type something</label>
<div class="controls">
{{ Form::text('name', null , array('required' => '')) }}
<p class="help-block"></p>
</div>
</div>
{{ Form::submit('submit')}}
</form>
This worked fine and produced the error "This is required". I swapped in your form field and added in the
'required' => ''
to the end of your attribute array and that too worked just fine. Alternatively you could instead add in
'required' => 'required'
as jqBootstrapValidation picks up either. Good luck.

Resources