Im using CHtml::link() for attachment in my grid view and if i click on it, it will open in new tab to display.
My doubt is how can i use font awesome icon to display attachment in grid. Currently it showing from table but i want to display <i class="fa fa-paperclip" aria-hidden="true"></i> this icon for that column.
array(
'name' => 'invoice_attachment',
'value' => 'CHtml::link($data->invoice_attachment, Yii::app()->request->baseUrl.$data->invoice_attachment, array("target"=>"_blank"))',
'type' => 'raw',
),
The above code is my current output for link.
CHtml::link($text, $url, $htmlOptions) method accepts 3 parameters:
$text - this is what you want, right now youre setting here $data->invoice_attachment (propably file name) - change this to your <i> string
$url - a URL or an action route that can be used to create a URL
$htmlOptions - additional HTML attributes
Change $text param and that's all.
Related
I have the following code on my form:
<?php
$unitPrices = ArrayHelper::map(Item::find()->where('isApproved and
vendor_id=:id', [':id' => $vendorId])->all(),'id','unitPrice');
?>
this gives me a map called unitPrices where the key-value pairing is id-unitPrice
<?= $form->field($model, 'item_id')->dropDownList(
ArrayHelper::map(Item::find()->where('isApproved and vendor_id=:id', [':id' => $vendorId])->all(),'id','itemCode','description'),
[
'prompt'=>'--Select Item--',
'id'=>'item_selected',
'onchange' => '$("#priceOnLine").val($unitPrices[item_id_value]);',
])
?>
what I want to do is when an item is selected from the dropdownlist, it also sets the value of a text field called priceOnLine using the unitPrices map where the id is the value of the selected item from the dropdownlist.
I tried setting the text field to a static value (100), and it works but I can't figure out how to set it using the map.
'onchange' => '$("#priceOnLine").val(100);',
Thanks in advance for the help :D
You need to get the text of the selected option you can add the following script on the top of your view and remove the 'onchange' => '$("#priceOnLine").val($unitPrices[item_id_value]);', from your dropDown()
<?php
$js=<<<JS
$("#item_selected").on("change",function(){
$("#priceOnLine").val(($(this).find("option:selected").text()));
});
JS;
$this->registerJs($js,\yii\web\View::POS_READY);
Hope it helps
I have a problem here which i am working quite a while but do not have any ideas left for a solution. I will try to make it short:
I use the eColumns extension for the admin and the view module in yii. I added a combobox to select views which are saved in the database so that users can build their own selection of select columns for each table, however:
In eColumns i added a button to delete an already created selection and an input field to give the selection a name
CHtml::button('', array('type' => 'submit','name' => 'btn_delete','value' => 'Ansicht löschen', 'onclick' => '$("#'.$this->getId().'").dialog("close");', 'style' => 'align: left', 'confirm'=>'Sind sie sicher das sie diese Ansicht löschen möchten?'));
CHtml::textField('input_name', substr($this->selectedView,strpos($this->selectedView,"##")+2), array('size'=>30,'maxlength'=>200));
If i click the button in the view-module everything works as expected. $_POST is filled with "input_name" and "btn_delete". However if i this same code included in the admin-module only input_name is filled - btn_delete is simply not set if i click the button.
Anybody can i give me any hint what i can check?
Thanks in advance! :)
If you are using jQuery serialize() to collect form elements in your admin-module, jQuery serialize() will not serialize any submit button value.
See also serialize example, hope this will help. :)
=== links to jsfiddle must be accompanied by code.. ===
html
<form>
<input type="text" name="text" value="text-value">
<input type="submit" name="submit-btn" value="button-value">
</form>
<span name="result-serialize"></span>
jQuery
var serializeString = $("form").serialize();
$("span[name=result-serialize]").text(serializeString);
I'm using yiibooster and it is really good extension for the frontend, my issues now is that I want to remove the red * that is rendered in the required fields but maintaining the required validator in the model, anyone knows how to do this????
thankss
This is an example of a label generated by a required field validator:
<label for="User_email" class="required">
Email Address <span class="required">*</span>
</label>
Therefore, you can hide it by adding this class to your site's CSS:
span.required {
display: none;
}
If you want to achieve what you want easily, I suggest you to do like below, which is simplest way(in my view point):
Just try to find * selector(the ID or CLASS) name.(using a firebug or any inspector)
Then just do like below in your document.ready():
$(SELECTOR).remove();
NOTES
THE * MIGHT BE CREATED DYNAMICALLY
THIS IS JUST AN SUGGESTION, YOU CAN FIND ANY OTHER POSSIBLE WAYS SUCH AS CHANGING THE CSS CLASS IN ORDER TO DO DISPLAY:NONE OR SOURCE MODIFICATION
<?php echo $form->textFieldGroup($model, 'username',array('label'=>Yii::t('model','Username'))); ?>
or edit line 1223 of TbActiveForm.php from
echo $this->labelEx($model, $attribute, $options['labelOptions']);
to
echo $this->label($model, $attribute, $options['labelOptions']);
Red * is adding according to your validators definition in your model. you have two options.
First in your model add On => 'scenario name' for required validator for the property you want. so you can control the behavior of yii-booster components because they only apply those rules which matches the scenario of the model. for example:
array('password_repeat', 'required', 'on'=>'register'),
It will show Red * only in register scenario (if you set it via $model->setScenario('register');) and in normal times no red * will shown.
Another option for you is when you are creating the form element based on the property marked required by validator rules in model, you can prevent that * from showing but this way will not ignore that validation rule and if you try to submit the form while this form field is empty you will get error from yii (because you just solve showing but in background you have your required validator). for this method, you only need to provide label in your yii-booster form element:
<?php echo $form->textFieldGroup($model,'textField',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'hint' => 'In addition to freeform text, any HTML5 text-based input appears like so.',
>>>>> 'label' => 'Your new value for label which will have no red *',
)
); ?>
I was looking to put a dynamic popup dialog in a yii menu but am missing a trick to make it dynamic. (edited: or maybe the question should be 'How can I pass a widget some text through a variable from a menu array) As per the code below:
/*Create A Popup Dialog (Gets called from menu)*/
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'mydialog',
'options'=>array(
'title'=>'Menu Alert',
'autoOpen'=>false,
),
));
echo $dialogText; //Dynamic rather than just static text
$this->endWidget('zii.widgets.jui.CJuiDialog');
/* End of Popup Menu*/
//------------------------------------------------
$this->menu=array(
array('label'=>'Help', 'url'=>array('xyz'),'linkOptions' => array('onclick' => '$("#mydialog").dialog("open"); return false;','dialogText'=>'Available Soon')),
);
When I use this code, a dialog box appears without the dialog message 'Available Soon'
Use text instead of dialogText and place it before dialog open
array('label'=>'Help', 'url'=>array('xyz'),'linkOptions' => array('onclick' => '$("#mydialog").text("Available soon"); $("#mydialog").dialog("open"); return false;')),
Hello and thanks for reading my question. I have a typical list view:
<?php $this->widget('bootstrap.widgets.TbListView',array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'emptyText'=>'No Jobs',
)); ?>
In my _view file I have a div and a button that slideToggles the div. If I just put the Javascript at the top of the page, it does not work because the results are dynamic and the name of the div changes with the id returned, eg:
id="detailsDiv-<?php echo $data->id_employer_contract;?>"
The problem is in my Javascript, which is as follows:
<?php Yii::app()->clientScript->registerScript('details', "$('#details-$data-id_employer_contract').click(function(){
$('#detailsDiv-$data->id_employer_contract').slideToggle();
return false;});");?>
How can I make this Javascript code dynamic? Meaning, how can I loop through the id? I tried adding the code to the listview property ajaxUpdate but it's still not working. Can someone tell me how I can loop a Javascript in a list view?
Add the id to your toggle buttons as data attribute:
<button class="toggleDetails" data-id="<?php echo $data->id_employer_contract ?>">
Then you can access these data attributes like this js:
<?php Yii::app()->clientScript->registerScript('toggleDetails', "
$('.toggleDetails').click(function(e){
var id = $(this).data('id');
$('#detailsDiv-' + id).slideToggle();
e.preventDefault();
});
", CClientScript::POS_READY) ?>
NOTE: You should not put this javascript into _view.php but into the main file where you render the List View. You only need this one single snippet to deal with all your buttons.