Adding a class to all checkboxes in cakephp (HABTM) - cakephp

I have to tables associated with HABTM, and it displays the checkboxes perfectly. The line of code is this:
<?php echo $this->Form->input('Item.ItemCharacteristic',array('id'=>'item_characteristic','label' =>false,'type'=>'select','multiple'=>'checkbox','options' => $itemCharacteristics,'selected' => $this->Html->value('ItemCharacteristic.ItemCharacteristic')));
?>
what it displays is this:
<div class="input select"><input type="hidden" name="data[Item][ItemCharacteristic]" value="" id="item_characteristic"/>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="8" id="item_characteristic8" /><label for="item_characteristic8">We-Fii</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="9" id="item_characteristic9" /><label for="item_characteristic9">Test1</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="10" id="item_characteristic10" /><label for="item_characteristic10">Setting</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="11" id="item_characteristic11" /><label for="item_characteristic11">Test4</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="13" id="item_characteristic13" /><label for="item_characteristic13">Solari</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="15" id="item_characteristic15" /><label for="item_characteristic15">Panorama</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="17" id="item_characteristic17" /><label for="item_characteristic17">BlusBrothers</label></div>
</div>
so what i want is to add a class within iput element like this:
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="8" id="item_characteristic8" class="element" /><label for="item_characteristic8">We-Fii</label></div>
so just to add the class="element" to it..
Any ide??

You can placed your class on the field by adding 'class' => 'name' to the array
<?php echo $this->Form->input('Item.ItemCharacteristic',array('class'=>'mycustomclass' 'id'=>'item_characteristic','label' =>false,'type'=>'select','multiple'=>'checkbox','options' => $itemCharacteristics,'selected' => $this->Html->value('ItemCharacteristic.ItemCharacteristic')));
?>
I hope it solves your problem

Related

Can't store data using checkbox to database using codeigniter

I try to store some data using checkbox into my database, but it can't stored. Here is my code:
I try to store some data using checkbox into my database, but it can't stored. Here is my code:
I try to store some data using checkbox into my database, but it can't stored. Here is my code:
View:
<form method="post" action="<?php echo base_url().'igd/igd/input_airborne'?>">
<?php echo $this->session->flashdata('message_airborne');?>
<input type="text" class="form-control" name="KUNJUNGAN" value="<?php echo $igd->NOMOR ?>" readonly>
<input type="datetime-local" class="form-control" name="TANGGAL" value="<?php echo date("Y-m-d H:i:s") ?>">
<input type="text" class="form-control" name="OLEH" value="<?php echo $session_user->nip?>" readonly>
<input type="text" class="form-control" name="STATUS" value="1" readonly>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" name="DESKRIPSI" id="defaultCheck1">
<label class="form-check-label" for="defaultCheck1">
TBC AKtif
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" name="DESKRIPSI" id="defaultCheck2">
<label class="form-check-label" for="defaultCheck2">
Campak
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" name="DESKRIPSI" id="defaultCheck1">
<label class="form-check-label" for="defaultCheck1">
MDR TB
</label>
</div>
<button class="btn btn-sm btn-success mt-1 mb-1"> Masukkan</button>
</form>
Controller:
public function input_airborne(){
$DESKRIPSI = $this->input->post('DESKRIPSI');
$TANGGAL = $this->input->post('TANGGAL');
$OLEH = $this->input->post('OLEH');
$STATUS = $this->input->post('STATUS');
$KUNJUNGAN = $this->input->post('KUNJUNGAN');
$data = array(
'DESKRIPSI' => $DESKRIPSI,
'TANGGAL' => $TANGGAL,
'OLEH' => $OLEH,
'STATUS' => $STATUS,
'KUNJUNGAN' => $KUNJUNGAN
);
$this->M_Igd->input_airborne($data, 'igd_inim_airborne');
$this->session->set_flashdata('message_airborne','<div class="alert alert-success alert-dismissible mt-1 fade show" role="alert">
Airborne berhasil dimasukkan
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>');
redirect($_SERVER['HTTP_REFERER']);
}
the DESKRIPSI is field to storing my checkbox entry
it's been solved, i just change
$DESKRIPSI = $this->input->post('DESKRIPSI');
to
$DESKRIPSI = implode(', ', $_POST['DESKRIPSI']);
and don't forget to change name to
name="DESKRIPSI[]";
because data will be stored as array
You should specify:-
<input type="checkbox" name="Days[]" value="Daily">Daily<br>
Add [] to all names Days and work at php with this like as array.
After it, you can INSERT values at different columns at db, or use implode and save values into one column.
<html>
<body>
<form method="post" action="chk123.php">
Flights on: <br/>
<input type="checkbox" name="Days[]" value="Daily">Daily<br>
<input type="checkbox" name="Days[]" value="Sunday">Sunday<br>
<input type="checkbox" name="Days[]" value="Monday">Monday<br>
<input type="checkbox" name="Days[]" value="Tuesday">Tuesday <br>
<input type="checkbox" name="Days[]" value="Wednesday">Wednesday<br>
<input type="checkbox" name="Days[]" value="Thursday">Thursday <br>
<input type="checkbox" name="Days[]" value="Friday">Friday<br>
<input type="checkbox" name="Days[]" value="Saturday">Saturday <br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
At PHP Server Side Script:-
$checkBox = implode(',', $_POST['Days']);

How to show auto selected to radio buttons when it comes from Loop?

I have a small application of attempt online exam. My questions set are comes from DB using loop. I want to edit my already attempted exam. I have a answer set of questions. But I am not able to show auto select to attempt radio buttons.
Here is my answer set
{"1":"A","2":"A","6":"A","10":"A","14":"A","21":"B","26":"C","31":"B","33":"C","34":"B","54":"C"}
Here my questions which I am showing on view page using loop
<div class="row" style="margin-top: 20px;">
<section ng-repeat="count in subject.test_count" ng-cloak class="col col-3">
<div class="inline-group" ng-if="count%2!='0'">
<b style="width: 25px;display: inline-grid;">{{count}}</b>
<input type="radio" name="{{subject.name}}{{count}}"
id="a{{subject.name}}{{count}}" class="input-hidden"
ng-model="questiondata[subject.name][count]"
value="A" ng-checked="true">
<label for="a{{subject.name}}{{count}}" >
<p>A</p>
</label>
<input type="radio" name="{{subject.name}}{{count}}"
id="b{{subject.name}}{{count}}" class="input-hidden"
ng-model="questiondata[subject.name][count]" value="B">
<label for="b{{subject.name}}{{count}}" >
<p>B</p>
</label>
<input type="radio" name="{{subject.name}}{{count}}"
id="c{{subject.name}}{{count}}" class="input-hidden"
ng-model="questiondata[subject.name][count]" value="C">
<label for="c{{subject.name}}{{count}}" >
<p>C</p>
</label>
<input type="radio" name="{{subject.name}}{{count}}"
id="d{{subject.name}}{{count}}" class="input-hidden"
ng-model="questiondata[subject.name][count]" value="D">
<label for="d{{subject.name}}{{count}}" >
<p>D</p>
</label>
<input type="radio" name="{{subject.name}}{{count}}"
id="e{{subject.name}}{{count}}" class="input-hidden"
ng-model="questiondata[subject.name][count]" value="E">
<label for="e{{subject.name}}{{count}}" >
<p>E</p>
</label>
</div>
</section>
There are a couple things that are off with this. First is that you are ngRepeating through the values of the test_count and not the actual objects, to resolve that you're going to want to do something like this:
<section ng-repeat="(key,value) in subject.test_count" ng-cloak class="col col-3">
{{key}} {{value}}
<span class="inline-group" ng-if="count%2!='0'">
<input type="radio" name="{{subject.name}}{{key}}"
id="a{{subject.name}}{{key}}" class="input-hidden"
ng-model="questiondata[subject.name][key]"
value="A">
<label for="a{{subject.name}}{{key}}" >A</label>
<input type="radio" name="{{subject.name}}{{key}}"
id="b{{subject.name}}{{key}}" class="input-hidden"
ng-model="questiondata[subject.name][key]" value="B">
<label for="b{{subject.name}}{{key}}" >B</label>
<input type="radio" name="{{subject.name}}{{key}}"
id="c{{subject.name}}{{key}}" class="input-hidden"
ng-model="questiondata[subject.name][key]" value="C">
<label for="c{{subject.name}}{{key}}" >C</label>
<input type="radio" name="{{subject.name}}{{key}}"
id="d{{subject.name}}{{key}}" class="input-hidden"
ng-model="questiondata[subject.name][key]" value="D">
<label for="d{{subject.name}}{{key}}" > D</label>
<input type="radio" name="{{subject.name}}{{key}}"
id="e{{subject.name}}{{key}}" class="input-hidden"
ng-model="questiondata[subject.name][key]" value="E">
<label for="e{{subject.name}}{{key}}" >E</label>
</span>
</section>
Once you have your radio buttons and subject matching (I took some liberty with how I think you'd have the data setup) you need to seed the questiondata using the values you've provided above:
$scope.questiondata[0] = angular.copy($scope.subject.test_count);
Now we can see that $scope.questiondata[0][1] = $scope.subject.test_count[1] = 'A' which means that A will be selected.
Here is a sample of the full controller: https://plnkr.co/edit/fyJwfLc6Qb7b7p4ZLgqI

Using ng-model and ng-if to show elements based on value - Angular 2

So in AngularJS i was using the following to show specific form elements based on a value that is captured by a model:
<fieldset class="full-width sm-padding">
<label>Do you have any major medical conditions such as
heart conditions, cancer or diabetes?</label>
<div class="inline-flex">
<input type="radio" name="medicalCondition" value="yes"
tabindex="16" ng-model="clientDetails.medicalCondition">Yes<br>
</div>
<div class="inline-flex">
<input type="radio" name="medicalCondition" value="no"
tabindex="17" ng-model="clientDetails.medicalCondition">No<br>
</div>
</fieldset>
<fieldset class="full-width sm-padding" ng-
if="clientDetails.medicalCondition == 'yes'">
<label>Are you currently taking any medication or do you
have any other medical conditions? For example HBP, Cholesterol, Asthma,
Depression? (Both lives if cover for couple)</label>
<div class="inline-flex">
<input type="radio" name="otherMedicalCondition"
value="yes" tabindex="18" ng-
model="clientDetails.otherMedicalCondition">Yes<br>
</div>
<div class="inline-flex">
<input type="radio" name="otherMedicalCondition"
value="no" tabindex="19" ng-
model="clientDetails.otherMedicalCondition">No<br>
</div>
</fieldset>
How can I do the same thing in Angular 2?
Have tried this but not working:
<fieldset class="full-width sm-padding">
<label>Do you smoke?</label>
<div class="inline-flex">
<input type="radio" name="smoker" value="yes"
tabindex="12" [(ngModel)] = "clientDetails.smoker">Yes<br>
</div>
<div class="inline-flex">
<input type="radio" name="smoker" value="no" tabindex="13" [(ngModel)] = "clientDetails.smoker">No<br>
</div>
</fieldset>
<div class="full-width flex" *ngIf="clientDetails.smoker ===
'Yes'">
<fieldset class="one-quarter sm-padding">
<label>What do you smoke?</label>
<input list="whatDoYouSmoke" name="whatDoYouSmoke"
tabindex="14">
<datalist id="whatDoYouSmoke">
<option value="Cigarettes">
<option value="Cigars">
<option value="Pipe">
<option value="E-Cigs">
<option value="Other">
</datalist>
</fieldset>
<fieldset class="one-quarter sm-padding">
<label>How many per day?</label>
<input type="number" min="0" name="howManySmokesPerDay"
tabindex="15">
</fieldset>
</div>
What am I doing wrong?
Have tried so many different options but can't quite get it to work!
thanks
The only thing I can see is that you have typed [(ngModel)] = "", try without spaces like: [(ngModel)]="". Also noticed that in your *ngIf="clientDetails.smoker ===
'Yes'", try with a little 'y' in yes as: *ngIf="clientDetails.smoker ===
'yes'". Since you are setting the value to "yes" and not "Yes" in your radio button.
There is a case problem in the Angular version. The first 'yes' starts with a lower case y and a second 'Yes' with a upper case Y.
For anyone out there looking for a solution to this, I ended up doing the following:
<fieldset class="full-width sm-padding">
<label>Do you smoke?</label>
<div class="inline-flex">
<input type="radio" name="smoker" [(ngModel)]="smoker"
[value]="true" [checked]="smoker" /> Yes<br>
</div>
<div class="inline-flex">
<input type="radio" name="smoker" [(ngModel)]="smoker"
[value]="false" [checked]="!smoker" /> No<br>
</div>
</fieldset>
<div class="full-width flex" *ngIf="smoker">
<fieldset class="one-quarter sm-padding">
<label>What do you smoke?</label>
<input list="whatDoYouSmoke" name="whatDoYouSmoke" tabindex="14">
<datalist id="whatDoYouSmoke">
<option value="Cigarettes">
<option value="Cigars">
<option value="Pipe">
<option value="E-Cigs">
<option value="Other">
</datalist>
</fieldset>
<fieldset class="one-quarter sm-padding">
<label>How many per day?</label>
<input type="number" min="0" name="howManySmokesPerDay"
tabindex="15">
</fieldset>
</div>

how to create dynamic inputs using ng-repeat and $index

I am trying to iterate over array of questions. But I need to attach radio button answers to each question.
In this case I need to add different ng-models for each answer.
I tried the code below but it didn't work.
Is this the correct way of using $index of the ng-repeat?
<li class="fields" ng-repeat="question in questions">
<p>question:{{question.title}}</p>
<div class="radio-buttons">
<input type="radio" id="radio01" value="0" ng-model="answer[$index]" checked="checked"/>
<label for="radio01"><span></span>Yes</label>
<input type="radio" id="radio02" value="1" ng-model="answer[$index]"/>
<label for="radio02"><span></span>No</label>
</div>
</li>
you need to do it like this modelname{{$index}}
<li class="fields" ng-repeat="question in questions">
<p>question:{{question.title}}</p>
<div class="radio-buttons">
<input type="radio" id="radio01" value="0" ng-model="answer{{$index}}" checked="checked"/>
<label for="radio01"><span></span>Yes</label>
<input type="radio" id="radio02" value="1" ng-model="answer{{$index}}"/>
<label for="radio02"><span></span>No</label>
</div>
</li>
You can also do it via square bracket notation too if that pleases you aesthetically more:
<li class="fields" ng-repeat="(i, question) in questions">
<p>question:{{question.title}}</p>
<div class="radio-buttons">
<input type="radio" id="radio01" value="0" ng-model="answer[i]" checked="checked"/>
<label for="radio01"><span></span>Yes</label>
<input type="radio" id="radio02" value="1" ng-model="answer[i]"/>
<label for="radio02"><span></span>No</label>
</div>
</li>
Also to note, models are better when expressed as dot models. So for example:
<input type="radio" ng-model="answer[i]" />
Would be better as:
<input type="radio" ng-model="models.answer[i]" />
Then in your controller this makes it simple to list all the models via the object 'models', rather than finding out how many answer[i] models there are.

Problems tick checkbox using PHPUnit (Functional tests)

I have problems to select the checkbox of the following code via PHPUnit.
<div id="user_project">
<input type="checkbox" id="user_project_1" name="user[project][]" value="1" checked="checked" />
<label for="user_project_1">Project 1</label>
<input type="checkbox" id="user_project_2" name="user[project][]" value="2" /><label for="user_project_2">Project 2</label>
<input type="checkbox" id="user_project_3" name="user[project][]" value="3" checked="checked" />
<label for="user_project_3">Project 3</label>
<input type="checkbox" id="user_project_4" name="user[project][]" value="4" checked="checked" />
<label for="user_project_4">Project 4</label>
<input type="checkbox" id="user_project_5" name="user[project][]" value="5" checked="checked" />
<label for="user_project_5">Project 5</label>
<input type="checkbox" id="user_project_6" name="user[project][]" value="6" checked="checked" />
<label for="user_project_6">Project 6</label>
<input type="checkbox" id="user_project_7" name="user[project][]" value="7" />
<label for="user_project_7">Project 7</label>
<input type="checkbox" id="user_project_10" name="user[project][]" value="10" /><label for="user_project_10">Project 10</label>
<input type="checkbox" id="user_project_12" name="user[project][]" value="12" /><label for="user_project_12">Project 12</label>
<input type="checkbox" id="user_project_13" name="user[project][]" value="13" />
<label for="user_project_13">Project 13</label>
</div>
Normally I will tick the checkboxes using "$form["Name of checkbox"]->tick();" - but i cannot change the name (because it is generated via Symfony2).
Can somebody help me?
Suppose you retrieve the form in the $form object, try this for select the 2nd element:
$select = $form->get('user[project]');
$cb = $select[1]; // the second table row
$cb->tick();
Hope this help

Resources