Just starting to learn the Yii. I do not know how to change the button and remove the "No files selected" in the widget
"CMultiFileUpload" in Yii framework?
$this->widget('CMultiFileUpload', array(
'model'=>$model,
'attribute'=>'photos',
'accept'=>'jpg|jpeg|gif|png',
'name'=>'photos',
'remove'=>'remove',
'options'=>array(
),
'denied'=>'File is not allowed',
'max'=>4, // max 10 files
));
This is browser dependent. Ex. Mozilla shows the input file type field with "No files selected". In IE it will come defferently.
If you want to hide the message "No files selected", do it with CSS
input[type='file']
{
color: transparent;
}
If you want to customize more, Try this bellow code.
Add this CSS code in your CSS file
#multFileUpload button#fileAlt
{
border: 3px solid #cccccc;
background-color: #FF7B10 !important;
color: #ffffff;
font-size: 14px;
padding: 10px 5px;
cursor: pointer;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
#multFileUpload input[type='file']
{
display: none;
}
Add this jQuery code in your javascript file
$(document).ready(function()
{
var maxFiles = 4;
var fileCountStart = 0;
$("#fileAlt").on('click', function()
{
fileCountStart += 1;
if (maxFiles >= fileCountStart)
{
$('#photos').trigger('click');
if (fileCountStart == maxFiles)
$("#fileAlt").attr('disabled', 'disabled');
}
});
});
Now Yii code
<div id="multFileUpload">
<button id="fileAlt">Select an Image</button>
<?php
$this->widget('CMultiFileUpload', array(
'model' => $model,
'id'=>'photos',
'attribute' => 'photos',
'accept' => 'jpg|jpeg|gif|png',
'name' => 'photos',
'remove' => 'remove',
'options' => array(
),
'denied' => 'File is not allowed',
'max' => 4, // max 10 files
));
?>
</div>
Related
I am displaying the text that is coming from the API as a badge and I want to filter certain things from it and I want to display the badge for each word that comes from the API.
Here is the code:
<span class="badge_style" id="badge" v-if="text.name">{{text.name | displayDesired}}</span>
...
text: [],
...
filters: {
displayDesired: function (val){
return val.replace(/_/g, ' ')
},
created() {
this.$http.get(`/all-text`)
.then((res) => { this.text = res.data })
.catch((err) => {console.log(err)})
}
...
.badge_style {
display: inline-block;
padding: .25em .4em;
font-size: 85%;
font-weight: 700;
line-height: 1;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
border-radius: .25rem;
text-transform: capitalize;
},
#badge {
color: white;
font-size: 12px;
background: blue;
}
{{text.name}} displays => The badge looks like this change_plan1|change_plan2|change_plan3 this is what I am getting from the API.
{{text.name | displayDesired}} with text-transform style displays => Change Plan1|Change Plan2|Change Plan3here the pipe should be replaced by the space and should get a separate badge.
Expected display => The badge should look something like this Change Plan1 Change Plan2 Change Plan3
Please tell me how to achieve the expected output
Convert your filter to method as following
methods: {
displayDesired: function (val){
return val.replaceAll('_', ' ').split('|');
},
as make the template as below:
<span id="badge" v-if="text.name">
<template v-for="(val, i) in displayDesired(text.name)">
<span class="badge_style" style="margin: 2px 2px 2px;" :key="i">{{ val }} </span>
</template>
</span>
In my Project (ATM Tiller machine) I am trying to display a drop down list, but its displaying in grid format, because in my current project all dropdown displaying in grid/table format only, because these ddl are having very less records.
But I want i display dropdownlist with 100 records, so Table/Grid format is not possible, could you please help me how to display dropdown using MVC4.
XX.cshtml code:-
var listBankNames = GetDropdownData(Model.AvailableBankList);
#Html.DropDownListFor(model => model.Bankname.Value, listBankNames, "", null)
At present result is showing as Grid format, But I need dropdownlist.
If you are using bootstrap in your project, then add a class to your dropdown like bellow,
#Html.DropDownListFor(model => model.Bankname.Value, listBankNames,
"--Select--", new { #class = "form-control dropdownlist" })
Or else add a class to your dropdown and override the style in CSS,
#Html.DropDownListFor(model => model.Bankname.Value, listBankNames,
"--Select--", new { #class = "myDropdown" })
In your CSS,
.myDropdown
{
display: inline-block !important;
position: absolute !important;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 12px 16px;
z-index: 1;
}
How can i add dollar symbol to the mvc value
#Html.TextBoxFor(x => x.RefundAmount, new { #class = "form-control", id = "RefundAmount", name = "RefundAmount",disabled="disabled" })
#Html.TextBoxFor(model => model.RefundAmount, new { #class = "required numeric", Value=String.Format("$ {0}",Model.RefundAmount) })
Try this
#Html.TextBoxFor(x => "$"+x.RefundAmount, new { #class = "form-control", id = "RefundAmount", name = "RefundAmount",disabled="disabled" })
Try this above code
Add to view :
*put $ sign between i tags
<div class="input-icon">
#Html.EditorFor(model => model.Sample,new {htmlAttributes = new { #class ="txt form control"} })
<i>$</i> ($ sign between the i tags)
</div>
#Html.ValidationMessageFor(model => model.Sample, "", new { #class = "text-danger" })
css:
.input-icon {
position: relative;
}
.input-icon > i {
position: absolute;
display: block;
transform: translate(0, -50%);
top: 50%;
pointer-events: none;
width: 35px;
text-align: center;
font-style: normal;
}
.input-icon > input {
padding-left: 20px;
padding-right: 0;
}
for more details check link here
I want my menu to have more than 2 levels. Looks like Yii 2 only renders up to 2 levels. For example this:
NavBar::begin();
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => [
[
'label' => 'Level 1',
'items' => [
['label' => 'Level 2 - 1', 'url' => '#'],
['label' => 'Level 2 - 2', 'url' => '#'],
[
'label' => 'Level 2 - 3',
'items' => [
['label' => 'Level 3 - 1', 'url' => '#'],
['label' => 'Level 3 - 2', 'url' => '#'],
],
],
]
],
],
]);
NavBar::end();
will not display the Level 3 - x menu items. How do I add more levels to the menu?
This is not Yii 2 limitation, it's Boostrap 3 limitation.
Here is quote from mdo (one of the main Boostrap 3 contributors):
We haven't seen anyone using submenus in meaningful ways and the code
necessary to make them work well is just too much overhead. Submenus
just don't have much of a place on the web right now, especially the
mobile web. They will be removed with 3.0.
It's taken from here.
However you can find some alternatives to use more levels. For example take a look this extension.
Also this question is discussed with more details and examples here.
1) Add Css in /web/css/site.css
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
-webkit-border-radius: 0 6px 6px 6px;
-moz-border-radius: 0 6px 6px;
border-radius: 0 6px 6px 6px;
min-width: 200px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #ccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #fff;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
-webkit-border-radius: 6px 0 6px 6px;
-moz-border-radius: 6px 0 6px 6px;
border-radius: 6px 0 6px 6px;
}
2) Add submenu and attributes 'itemsOptions' , 'submenuOptions', 'items':
...
[
'label' => 'Level 2 - 3',
'itemsOptions'=>['class'=>'dropdown-submenu'],
'submenuOptions'=>['class'=>'dropdown-menu'],
'items' => [
['label' => 'Level 3 - 1', 'url' => '#'],
['label' => 'Level 3 - 2', 'url' => '#'],
],
],
....
3) ok !!
Try to use this extension of Nav widget.
I used these settings
WickedPdf::config = {
:layout => 'application.pdf.html', # use 'pdf.html' for a pfd.html.erb file
:wkhtmltopdf => '/bin/wkhtmltopdf', # path to binary
:orientation => 'Portrait', # default , Landscape
:page_size => 'A4',
:dpi => '300',
:print_media_type => true,
:no_background => true,
:margin => {:top => 0, # default 10 (mm)
:bottom => 0,
:left => 0,
:right => 0},
}
and set the body style to
body {
margin: 0;
padding: 0;
background-color: #FFF;
width: 210mm;
height: 297mm;
}
and a div of class .page
.page {
display: inline-block;
clear: both;
border: 2px solid #FF0000;
width: 210mm;
height: 297mm;
page-break-after: auto;
}
but when the pdf is created, the .page divs are almost half of the pdf page.
If you are floating your page container, then it won't work. I had the exact same problem and once I removed the floating pro.
So your page container should be:
.page {
display: block;
clear: both;
border: 2px solid #FF0000;
page-break-after: auto;}
Because the inline-block is just like floating it left.
Try putting in your css
#media print
{ .page {
display: inline-block;
clear: both;
border: 2px solid #FF0000;
width: 210mm;
height: 297mm;
page-break-after: auto;
}
}
Also make sure you add media="all" if you are referencing external stylesheet:
<link href="/stylesheets/scaffold.css?1304060088"
media="all" rel="stylesheet" type="text/css">