How to use multidimensional checkbox v-model in vuejs - laravel-5

Suppose i have some subjects which has conditions and groups.
How can i load those first time and checked in update mood in vuejs?
<div v-for="(sub, Index) in subjects">
<b>{{ sub }} </b>
<label v-for="(subconlist) in sub['subCon']">
<input type="checkbox"
:value="subconlist.id"
:key="subconlist.id"
>
<span>{{subconlist.name}} </span>
</label>
<label v-for="clsgrlist in sublist['acGr']">
<input type="checkbox">
<span>{{clsgrlist.academic_group_name}} </span>
</label>
</div>
<button #click="saveOrUpdate()" >Save </button>
</div>
fiddle here
the table where i will save it : sub_id,condition_ids,group_ids
I have to save data based on checked value in the table with comma separated.
How can i get checkbox checked if it already found in the table, i mean when update?
I need to get subjectconditon or group ids basis on each subject when click on save button.

Related

How to get checked radio button with database value in edit blade in laravel 8

I have value for time column in database. In edit blade i need to show the value with checked radio button.
The code I have:
<div class="col-sm-12 col-md-6">
<div class="form-group">
<label for="slot" class="mb-2">Slot</label>
<div class="form-check">
<input class="form-check-input form-check-success" type="radio" name="time" id="time"
value={{$appointment->time}}" required>
<label class="form-check-label" for="time">{{$appointment->time}}</label>
</div>
</div>
</div>
according to this I am getting only the value with a blank radio button not checked radio button.

Laravel - Redirect users back to another form with all data intact, on clicking Previous button

I have two forms as below
Form 1
<form id="form1" action="loc1" method="post">
<div class="form-group">
<label for="exampleDOB">Date of Brth:</label>
<input type="text" class="form-control" id="dob" name="dob" placeholder="Date of Birth"
value="{{$tuser->DOB ?? ''}}" >
<div class="error text-danger"></div>
</div>
<button type="submit">Next Step</button><br><br>
<button type="button">Previous </button>
</form>
Form 2
<form id="form2" action="loc2" method="post">
<div class="form-group">
<label for="exampleMob">Mobile Number:</label>
<input type="text" class="form-control" id="mobno" name="mobno" placeholder="Valid Mobile
Number" value="{{$tuser->mobno ?? ''}}" >
<div class="error text-danger"></div>
</div>
<button type="submit">Final Step</button><br><br>
<button type="button">Previous </button>
</form>
$tuser is an object containing all the data for that user, from the database
When users click on Next Step in Form 1, the data is stored in database and the user is directed to Form 2.
But the problem is- on clicking the Previous button, I am losing all the pre-filled data in the Previous form. How can I retain form data (to be shown in the input fields as available in the database)?
if you have saved them in DB, so you can retrieve all of it using an id and store it in session like:
session->put("form_1_id",$DBInsertedId);
in form 1 you can check if there are any results, you can retrieve it like:
if(session->has("form_1_id"))
return view('form_1',['filled_data' => Model::find(session->get("form_1_id")) ]);
and in the view you can check for parameter existence form_1_id like you did:
<input type="text" class="form-control" id="dob" name="dob" placeholder="Date of Birth"
value="{{$filled_data->DOB ?? ''}}" >
just add a filled name id in your input view and fill it if form has been filled out before. since doing this can assure you that the filled form will be updated if there was a record for it before:
<input type="hidden" id="id" name="id" value="{{$filled_data->id ?? ''}}" >
and in your controller:
Model::insertOrUpdate(['id' => $request->id ], ... );
UPDATE:
insertOrUpdate Equivalent in psudo-code :
if(DB::exist(['id' => $request->id]))
update(['id' => $request->id , ... ]);
else
insert([ ... ]);

How to Apply form validation inside data table in angular2

I am trying to apply required field validation for text-box which is inside data table template.
Required field validation message pop up properly but as there is no form tag i was not able to check form.valid in component.
Please find below code:
<data-table id="user-grid"(reload)="reloadItems($event) [items]="userData">
<data-table-column [header]="'UserName'">
<template #dataTableCell let-item="item">
<span>
<input type="text" [(ngModel)]="item.UserName" class="form-control" required #UserName="ngModel" name="UserName"/>
<span class="text-danger" *ngIf="(UserName.errors != null && UserName.errors.required && (UserName.dirty))">
Please enter user name.
</span>
</span>
</template>
</data-table-column>
<data-table-column [header]="'Action'" >
<template #dataTableCell let-item="item">
<a title="Save" (click)="save(item)" class="btn green btn-sm">
</a>
</template>
</data-table-column>
</data-table>
Any help will be appreciable.
Put the datatable element inside the form tag having ngForm. It would fire the form validations.
Please see below:
<form #testform="ngForm">
<data-table>
</data-table>
</form>

Laravel: textarea does not refill when using Input::old

I am experiencing that only the Input Textfields respond as expected when I write the code to repopulate a form (when errors were found for example) or when from a table row I click in the Edit button and I go to an editable form. The field for a textarea is not repopulated so it comes up empty, therefore, if I save it, I would delete the content of the textarea. (I know I am asking a succession of questions lately, the reason is that I have basically finished my application and I left for the end the minor things I could not solve, so my apologies for that).
here is an example of what I am saying:
This WORKS for input textfield:
WORKS
<div class="col-md-4">
<label for="relato">Charges</label>
<input type="text" name="expenses" maxlength ="30" class="form-control"
value = "{{ $user->expenses }}"/>
</div>
That is, the $user->expenses fills the textfield of the form that comes up when clicking the Edit button of a table row.
However, that does not work for a textarea field:
<div class="row">
<label for="relato">Description</label>
<textarea name ="message" id="message" rows="5" cols="100" value = "{{ $user->message }} class="form-control"
</textarea>
</div>
See? that part $user->message will not pass the content to the textarea of a form.
Similarly: with Input::old
Works for an Input textfield
WORKS
Email: <input type="text" class="form-control" name="email" {{ (Input::old('email')) ?' value ="' . e(Input::old('email')). '"' : '' }}>
DOES NOT WORK FOR TEXTAREA
<div class="form-group">
<label for="relato">Une petite description</label>
<textarea id="message" name = "content" rows="10" cols="50" onKeyPress class="form-control" {{ (Input::old('content')) ?' value ="' . e(Input::old('content')). '"' : '' }}
">
</textarea>{{ $errors->first('content')}}
</div>
And the controller is also trying to refill the form by sending ->withInput
if($validator->fails()){
return Redirect::route('usersgetformtopostads')
->withErrors($validator)
->withInput();
}
but, as I said, it only works for textfields. Does not repopulate me a select list or a textrarea
By the way, I have looked a related question here where the author says he could not repopulate a File field and he was told that "you cant" and he gave that as a correct answer, however, I have been able to repopulate Files uploaded, not having any problem with that.
textarea does not have a value attribute. Values in textarea should be inside <textarea></textarea>, so in your case:
<textarea id="message" name = "content" rows="10" cols="50" onKeyPress class="form-control">
{{{ Input::old('content') }}}
</textarea>
Just figured it out, put the old value in between the brackets as below
<textarea name="message">{{ old('message') }}</textarea>
This is another way to do the same but with the Forms component from laravel:
{{ Form::textarea('content',Input::old('content'),array('id' => 'message')) }}
I'd like to add one thing, if you use Form Class for the form and elements then you don't need to explicitly right the Input::old('element-name') to retrieve the value of the previous form submission.
Just use
{{ Form::text('name', null, array('id'=>'name', 'class' => 'class-to-apply')) }}
And you're good to go.
Here, null value for the text field will be null for the first time, and if you redirect back this page with input then this will automatically grab the value.
Sorry for late reply
{{Form::textarea('mobile_message', isset($notifications -> mobile_message) ? $notifications -> mobile_message : null, 'id'=> 'mob_id','class' => 'form-control'))}}
<div class="control-group hidden-phone">
<label class="control-label" for="textarea2">Category Description</label>
<div class="controls">
<textarea style="resize:none" name="category_description" required rows="6">
<div class="control-group hidden-phone">
<label class="control-label" for="textarea2">Category Description</label>
<div class="controls">
<textarea style="resize:none" name="category_description" required rows="6" >{{$category_info->category_description}}</textarea>
</div>
</div>
</textarea>
</div>
Normally, textarea does not have a value attribute, but there's a way you can add that with the current Laravel version (which is 8+)
<textarea>{{{ Request::old('content') }}}</textarea>

How do I add user-chosen price to cart? (google checkout)

This example shows how to add a field to let customers to choose their own price. But the button in that example is for fast checkout. I am trying to add the customer-chosen price to cart? How do I do this?
The code that I have (google app engine - python) adds the item to the cart but not the price; the price is always zero. This is the code I am using:
self.response.out.write("""
$ <input type="text" name="item_price_1"/>
<div class="product">
<input type="hidden" class="product-title" value="%s">
<input type="hidden" class="product-attr-id" value="id#%s">
<div class="googlecart-add-button" tabindex="0" role="button" title="Add to cart">
</div></div>
And this is the sandbox script:
#sandbox script
self.response.out.write("""<script id='googlecart-script' type='text/javascript' src='https://checkout.google.com/seller/gsc/v2_2/cart.js?mid=1234567890' integration='jscart-wizard' post-cart-to-sandbox='true' currency='USD' productWeightUnits='LB'></script> """)
I solved the problem:
According to documentation, javascript to add the items to cart only processes
elements that appear within a tag that uses the CSS product class.
For example, in the HTML snippet above, if the price (and the
product-price class) appeared outside of the element,
the shopping cart JavaScript would not identify a price for the item.
So added $ <input type="text" name="item_price_1"/> inside the <div class="product"> as class="product-price":
<div class="product">
<input type="hidden" class="product-title" value="%s">
$ <input type="text" class="product-price" name="item_price_1"/>
<input type="hidden" class="product-attr-id" value="id#%s">
<div class="googlecart-add-button" tabindex="0" role="button" title="Add to cart">
</div></div>

Resources