How to loop into input check form? - laravel-9

I want to loop into checkbox form for checked. I used many to many relationship with laravel. I want to show into edit form auto checked.
<label class="form-check form-check-sm form-check-custom form-check-solid me-5 me-lg-20">
<input
class="form-check-input"
type="checkbox"
value="{{ $permission->id }}"
name="user_management[]"
{{ $check_permission[0] == $permission->name ? 'checked' : '' }}/>
<span class="form-check-label">{{ $permission->name }}</span>
</label>

Related

In this code i want to change the variable name 'frontenditems' and 'whoAmI' wheneve i clicked check and radiobutton but it is showing olny on

<template>
<p>FrontEnd Items</p>
<label for="vue">Vue.js</label>
<input type="checkbox" name="vue" id="vue" v-model="frontendItems">
<label for="React">React.js</label>
<input type="checkbox" name="React" id="React" v-model="frontendItems">
<label for="Angular">Angular.js</label>
<input type="checkbox" name="Angular" id="Angular" v-model="frontendItems">
<p>
You have selected :- {{ frontendItems }}
</p>
<p>For radio Buttons</p>
<p>Who am I</p>
<label for="developer">Developer</label>
<input type="radio" name="developer" id="developer" v-model="whoAmI">
<label for="programmer">Programmer</label>
<input type="radio" name="programmer" id="programmer" v-model="whoAmI">
<p>
I am :- {{ whoAmI }}
</p>
</template>
<script>
export default {
name : 'CheckRadiobinding',
data(){
return {
frontendItems:[],
whoAmI : null
}
}
}
</script>
In frontend items i want to get stored array values 'vue', 'react' and 'angular' and in whoAmI varaiable i want to get either developer or programmer whenever i click check and radio button but I am only getting 'on' as a value
You're missing value on each of your inputs. When a checkbox or radio input is selected value is what gets added to your v-model array
<template>
<p>FrontEnd Items</p>
<label for="vue">Vue.js</label>
<input
id="vue"
v-model="frontendItems"
value="Vue.js"
type="checkbox"
name="vue"
/>
<label for="React">React.js</label>
<input
id="React"
v-model="frontendItems"
value="React.js"
type="checkbox"
name="React"
/>
<label for="Angular">Angular.js</label>
<input
id="Angular"
v-model="frontendItems"
value="Angular.js"
type="checkbox"
name="Angular"
/>
<p>You have selected :- {{ frontendItems }}</p>
<p>For radio Buttons</p>
<p>Who am I</p>
<label for="developer">Developer</label>
<input
id="developer"
v-model="whoAmI"
value="Developer"
type="radio"
name="developer"
/>
<label for="programmer">Programmer</label>
<input
id="programmer"
v-model="whoAmI"
value="Programmer"
type="radio"
name="programmer"
/>
<p>I am :- {{ whoAmI }}</p>
</template>

VueJS checkbox with v-model and the ability to add a class

I am trying to output the value of individual checkboxes and also add a class to the label when the checkbox is checked. I can do one of the other but not both together. If I add :value="attendance" the output works as individual instances but the adding of the class doesn't work and if I add value="attendance" then it treats the 2 checkboxes as one value.
Can someone help please?
<div class="container">
<div class="row">
<div class="col-sm">
<label
class="btn btn-outline-primary label-in-filter"
:class="{
showattendances:
showattendancesisChecked('attendance'),
}"
v-for="attendance in uniqueattendances"
:key="attendance"
>
<!-- <input
value="attendance"
id="attendance"
name="showattendances"
class="ck-in-filter"
type="checkbox"
v-model="attendances"
/> -->
<input
id="attendance"
name="showattendances"
class="ck-in-filter"
type="checkbox"
:value="attendance"
v-model="attendances"
/>
{{ attendance }}
</label>
</div>
<p v-for="attendance in attendances" :key="attendance">
{{ attendance }}
</p>
</div>
</div>
methods: {
showattendancesisChecked(value) {
return this.attendances.includes(value);
},}

Set selected option NOT based on v-model

I have a select with v-model, but I need to set the selected option based on other values.
Is it possible?
This is what I've tried:
<div class="form-group">
<label for="">Category</label>
<select class="form-control" v-model="product.category">
<option v-for="(c, index) in categories" :value="c.id" :selected="product.category.id == c.id" :key="index">
{{ c.name }}
</option>
</select>
</div>
However, :selected seems to have no effect.
Just modify the v-model from
v-model="product.category"
to
v-model="product.category.id"
and remove
:selected="product.category.id == c.id"
You can read more about Form Input Bindings.

bind v-model to the property which does not exist (Array) in Vue JS

I have some questions getting from the database, It has options also. Then rendering those on the webpage.
like This
<div v-for="(question,index) in questions">
<div class="interview__item-text interview__text-main m-b-20">
{{ index+1 }}. {{ question.question }}
</div>
<div v-for="(option,index) in question.options"
class="reg__form-radioitem" :key="index">
<div>
<input class="checkbox countable__input"
v-model="question.answer"
:value="option.option"
type="checkbox"
:id="question.id+option.id">
<label :for="question.id+option.id">
{{ option.option }}
</label>
</div>
</div>
</div
This is working fine for input type text and radio but for checkbox it does not work. It checks all the checkboxes in that loop.
question.answer does not exist on the data.i am trying to add new property answer using v-model
Thanks.
Maybe you can try to predefine the question.answer, should exist after this:
data: {
question: {
answer: null
}
}
Try this.
<input class="checkbox countable__input"
v-model="question[answer]"
:value="option.option"
type="checkbox"
:id="question.id+option.id">
<label :for="question.id+option.id">
{{ option.option }}
</label>

v-model property doesn't show inside tinymce

I have v-model property, my problem is property doesn't show in tinymce even I can see it in inspect element.
<label>Nama : #{{ adDetailOrder.gajah }}</label>
<input type="text" name="nama" v-model="adDetailOrder.gajah" style="margin-bottom:0px" class="form-control" v-validate.initial="'required|alpha_spaces'" placeholder="Full Name">
<label>#{{ adDetailOrder.gajah }} ... ...</label>
<textarea id="description" class="form-control" rows="3" name="description">... #{{ adDetailOrder.gajah }} ...
</textarea>
Here is my vue
data: {
...
adDetailOrder: {
gajah: '',
}
Here is picture
this is someone is adDetailOrder.gajah
Where I'm doing wrong?
Thanks in advance.