Monday, 27 April 2015

check boxes , Radio buttons and user defined labels in YII

We can define style to the check boxes by inserting the below <script> code in <head> section of the view page:

<style>
input[type=checkbox]
    {
        /* Double-sized Checkboxes */
        -ms-transform: scale(2); /* IE */
        -moz-transform: scale(2); /* FF */
        -webkit-transform: scale(2); /* Safari and Chrome */
        -o-transform: scale(2); /* Opera */
        padding: 10px;
    }
    input.big {          
        font-size: 110%;
        display: inline;
    }
</style>


The declaration of check boxes and buttons in VIEW is

<?php echo CHtml::label("i) Registered Document", ''); ?>  /* Here the label is defined differently, if we define this way we have flexibility to change color text etc */

for example, CHtml::label("Details of DD in token of advanced payment<font color='red'> * </font>", '') 


<?php echo $form->checkBox($model,'married',array('value' => 'Y', 'uncheckValue'=>'N'),array('labelOptions'=>array('style'=>'display:inline'))); ?>

The above one is the check box, with field name 'married' if the field checked the value of married will be 'Y' otherwise 'N'.

Lets see some more examples

<?php echo $form->checkBox($model,'proof_sd',array('value' => 'Y', 'uncheckValue'=>'N'),array('labelOptions'=>array('style'=>'display:inline'))); ?>
<?php echo $form->checkBox($model,'proof_pt',array('value' => 'Y', 'uncheckValue'=>'N'),array('labelOptions'=>array('style'=>'display:inline'))); ?>
<?php echo $form->checkBox($model,'proof_eb',array('value' => 'Y', 'uncheckValue'=>'N'),array('labelOptions'=>array('style'=>'display:inline'))); ?>
<?php echo $form->checkBox($model,'proof_wb',array('value' => 'Y', 'uncheckValue'=>'N'),array('labelOptions'=>array('style'=>'display:inline'))); ?>
<?php echo $form->checkBox($model,'proof_bc',array('value' => 'Y', 'uncheckValue'=>'N'),array('labelOptions'=>array('style'=>'display:inline'))); ?>

The above code gives the following view image





coming to RADIO BUTTONS

We can declare them using

<?php echo CHtml::label("Land Area covered ", ''); ?>

<?php echo $form->textField($model,'area',array('size'=>10,'maxlength'=>10)); ?>

<?php echo $form->radioButtonList($model, 'areaunits', array('sqyd'=>'Sq. Yds','sqft'=>'Sq. Fts',  'sqmt'=>'Sq. Mts'),array('labelOptions'=>array('style'=>'display:inline; margin-right: 10px; font-weight: bold;'), 'separator'=>'&nbsp;&nbsp;',)); 
?>

Here the radio button linked to areaunits of model, so we have given the fieldname it may consists of values sqyd or sqft or sqmt. The area is entered in textbox and units to be selected by the user using the radio button. Here the units are either of the feet or yards or meters.

'sqyd' => 'Sq.Yds' means 'value'=>'label' the displayed text is Sq.Yds where are value sqyd is stored in the backend.


The above view is displayed.

another examples are,
<?php echo $form->radioButtonList($model, 'chklist', array('Y'=>'YES', 'N'=>'NO')
,array('labelOptions'=>array('style'=>'display:inline; margin-right: 10px; font-weight: bold;'),
    'separator'=>'&nbsp;&nbsp;',
)); ?>

That's it

we can use the check boxes, radio buttons as above way , There is no more code definitions in controller or model,

Hope this helps!!!













No comments:

Post a Comment