In yii2 basic ActiveForm i have added a drop-down list and in it used the "options" array to add my attributes .i want to add select2 in my drop-down but it is not working .i have searched on web and found this method of "options" array i have used below but still its showing no output in the view
<div class="col-xs-6 col-lg-6">
<div class="form-group form-material floating" data-plugin="formMaterial">
<div class="example"> <b role="presentation"></b>
<?= $form->field($model, 'corporation_status')->dropDownList(Yii::$app->appstatues->status,['options'=>['class'=>'form-control','prompt'=>'abc','data-plugin'=>'select2']])->label('Stat'); ?>
</div>
</div>
</div>
Any help would be much appreciated.
Use extension https://github.com/kartik-v/yii2-widget-select2
many good extensions is there too:
http://demos.krajee.com/
Found the solution for "select2" to be added to your drop-down list do the following steps:
Add following css and js files to your "AppAsset":
https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css
https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js
and in the form field add 'data-plugin'=>'select2' like this:
<?= $form->field($model, 'corporation_status')->dropDownList(Yii::$app->appstatues->status,['prompt' => 'hello','data-plugin'=>'select2','class'=>'form-control'])->label('Status'); ?>
Run this command to install kartik\select2 widget for yii2
php composer.phar require kartik-v/yii2-widget-select2 "#dev"
Then to use the widget.
//Include kartik\select2 Class
use kartik\select2\Select2;
// Normal select with ActiveForm & model
echo $form->field($model, 'corporation_status')->widget(Select2::classname(), [
'data' => Yii::$app->appstatues->status,
'options' => ['prompt' => 'Select a state ...'],
'pluginOptions' => [
'allowClear' => true
],
]);
Related
how do I insert a different icon for each widgets?
[
'type' => 'progress_white',
'class' => 'card mb-2',
'progressClass' => 'progress-bar bg-primary',
'value' => $userCount,
'description' => 'Utenti registrati.',
'progress' => (int)$userCount/10*100, // integer
'hint' => 'Numero di utenti registrati al portale.',
],
the html part is this this part below
<div class="{{ $widget['wrapperClass'] ?? 'col-sm-6 col-md-4' }}">
<div class="{{ $widget['class'] ?? 'card' }}">
<div class="card-body">
#if (isset($widget['value']))
<div class="text-value">{!! $widget['value'] !!}</div>
#endif
......
Unfortunately there is no way with the default widgets you will ave to create your own.
#if(isset($widget['icon']))
<div class="text-right" style="position:absolute;top:5px;right:15px;font-size: 40px;color: {{ $widget['icon_color'] ?? 'rgba(0,0,0,0.2)' }}">
<span class="{{ $widget['icon'] }}"></span>
</div>
#endif
Put that within the card-body class. Styling might need to be changed a little bit.
Other option is Backpack uses a new theme based on CoreUI. Can look at the documentation for CoreUI, or take a look at the source for the theme at https://backstrap.net
What kind of icons do you want? If you use icon set like material icon or awesome icon, you can pass your icon name and use it in "i" tag like this:
"icon" => "fa fa user"
and in your blade:
<i class"{{$widget['icon']}}"></i>
Pagination in laravel is showing blank page in pages other than first.
below is controller
$products=DB::table('products')->join('mobile_devices', 'products.id', '=', 'mobile_devices.product_id')->where('mobile_devices.brand', '=',$request->brand)
->where('mobile_devices.ram', '=', $request->ram)
->where('mobile_devices.storage', '=',$request->storage )
->select('products.*')->paginate(15);
below is blade
<div class="product-filter product-filter-bottom filters-panel">
<div class="row">
<div class="col-sm-6 text-left"></div>
<div class="col-sm-6 text-right">{{$products->links()}}</div>
</div>
</div>
working fine in eloquent result but in query result the problem is occuring. The first page is shown but in other pages just blank page appears
Do the properties request->ram and $request->storage carry over to the pagination links? They're probably not if you're not adding them in. See "Appending to Pagination Links" in the docs at https://laravel.com/docs/6.x/pagination#displaying-pagination-results
$products = DB::table(...);
$products->appends([
'ram' => $request->ram,
'storage' => $request->storage,
'brand_id' => $request->brand_id,
'brand' => $request->brand
]);
See also How to automatically append query string to laravel pagination links?
In your view,use the collection/result like this..
#foreach($products as $product)
{{$product->name}} // whatever you want to display
#endforeach
{{$products->links()}} // use the exact name of the object that you are passed to the view
Hi I am using laravel form binding along with
jqBootstrapValidation . In order to successfuly have the validate the input fields, I must pass something like "required" (without quotes) in the tag . Can you please let me know how can I achieve this ?
FYI .. the minlength works fine but the required does not work.
For example one of input elements currently looks as such
{{Form::text('username', null, array('class'=> 'form-control tip', 'data-toggle'=> 'tooltip', 'data-placement'=> 'bottom', 'title'=>'Enter your username that you have been using till now. This is a compulsory field.','placeholder'=>'Username ( must be filled )','minlength'=>'2'))}}
Thanks
You can't, take a look at the source code that builds the attributes:
protected function attributeElement($key, $value)
{
if (is_numeric($key)) $key = $value;
if ( ! is_null($value)) return $key.'="'.e($value).'"';
}
You'll always get a <attribute>=<name>, what you can test is to use it this way:
{{ Form::text('username',
null,
array( 'class'=> 'form-control tip',
'data-toggle'=> 'tooltip',
'data-placement'=> 'bottom',
'title'=>'Enter your username that you have been using till now. This is a compulsory field.',
'placeholder'=>'Username ( must be filled )',
'minlength'=>'2',
0 => 'required'
)
)
}}
It will build a tag
<... required="required" ...>
And it might work for jqBootstrapValidation.
Otherwise you'll have to create those inputs manually.
I've used this with the HTML attributes required="required" and also required="" works too. Changing the example they provide and adding in the Laravel Blade tags gives
<form class="form-horizontal" novalidate>
<div class="control-group">
<label class="control-label">Type something</label>
<div class="controls">
{{ Form::text('name', null , array('required' => '')) }}
<p class="help-block"></p>
</div>
</div>
{{ Form::submit('submit')}}
</form>
This worked fine and produced the error "This is required". I swapped in your form field and added in the
'required' => ''
to the end of your attribute array and that too worked just fine. Alternatively you could instead add in
'required' => 'required'
as jqBootstrapValidation picks up either. Good luck.
So from the product view i am getting related products to display. For reasons i wont get into i need to display the image of the related product but it has to be a custom image attribute. So i have created a custom image attribute called colour_swatch and i need to access it and display it on screen. I have done some reading on the issue and have not managed to find a solution to fit my needs.
So here is my code:
<?php foreach($this->getItems() as $_item): ?>
<div class="eachProductRelated">
<a href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" class="product-image">
<img src="<?php echo $this->helper('catalog/image')->init($_item, 'colour_swatch') ?>"
width="20px" alt="<?php echo $this->htmlEscape($_item->getName()) ?>"/>
</a>
</div>
<?php endforeach ?>
If we replace colour_swatch with small image that of course will work. I have read that you can't access a custom image attribute if you aren't calling it directly from the product view. And a lot of the solutions i have seen seem to be massively overkill, Surely there is a simpler solution???
Might be worth telling you that i get the following error message:
a:5:{i:0;s:25:"Image file was not found.";i:1;s:4015:"#0
/Users/Frank/Sites/bosideng/app/code/core/Mage/Catalog/Helper/Image.php(163):
Mage_Catalog_Model_Product_Image->setBaseFile(NULL)
Is it possible that i have to do some kind of if no_selected check ?
I have figured out this issue and pardon my French but it was a ridiculous and a stupid oversight by Magento.
When setting up your new custom image attribute you must set 'Use In Product Listing' to yes in the drop down before you select the attribute type 'Media Image' because guess what!? When you select Media Image, Magento hides that option.
Credit to this guy whose post i found after ages of searching: http://thedistance.co.uk/journal/2011-10/missing-magento-media-images
Hello i think you add new image url in custom image attribute then call may be help you
<img src="<?php echo Mage::getModel('catalog/product')->load($product)->getData('colour_swatch'); ?>"
For those of you creating custom image type using installer, add the following to make image visible on both listing and view pages:
$this->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'colour_swatch', array(
'group' => 'Images',
'type' => 'varchar',
'frontend' => 'catalog/product_attribute_frontend_image',
'label' => 'Color Swatch',
'input' => 'media_image',
'class' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'default' => '',
'used_in_product_listing' => true,
));
If Flat Catalog Category and Use Flat Catalog Product is set to Yes, then you can add the specific attributes to the collection
Like
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addAttributeToSelect('*');
$collection->addAttributeToSelect('attributes_name');
This is working perfect for me
I'm working on a Ruby and Sinatra project, and for a particular page I'm using jQuery mobile to create a mobile version of the page. I'm using knockout.js in the project as well.
I have a select box which appears correctly but when I make a selection, its text doesn't change though the value changes.
Here is my HAML code:
#subscriptions-content-div{'data-role' => 'content'}
%ol{'data-role' => 'listview', 'data-inset' => 'true', 'data-bind' => 'foreach: misspelt'}
%li
%h3{ 'data-bind' => 'text: show_name'}
- if shows.empty?
No Shows in Database
- else
%select#show
%option{'value' => 'no_choice', 'data-placeholder' => 'true'} Select a Show
- shows.each do |show|
%option{'value' => show.id}
= show.name
%button.btn{ 'data-bind' => 'click: $root.resolveSubscription', 'data-inline' => 'true', 'data-icon' => 'check', 'data-theme' => 'a'}
Save
This is the HTML I get when I view the page source:
<div data-role='content' id='subscriptions-content-div'>
<ol data-bind='foreach: misspelt' data-inset='true' data-role='listview'>
<li>
<h3 data-bind='text: show_name'></h3>
<select id='show'>
<option data-placeholder='true' value='no_choice'>Select a Show</option>
<option value='50594de40ea69713630000de'>
The Night Show
</option>
<option value='50594de40ea69713630000df'>
Another Show
</option>
<option value='50594de40ea69713630000e0'>
Yet Another Show
</option>
</select>
<button class='btn' data-bind='click: $root.resolveSubscription' data-icon='check' data-inline='true' data-theme='a'>
Save
</button>
</li>
</ol>
</div>
The menu has 'Select a Show' as the title. When I select something else, this doesn't change but the value changes. I can tell it changes when I get the value of the selected option. Why won't the text change?
The solution is to defer the selects' initialization until after the KO bindings have been applied. I added data-role="none" attributes to the select elements and manually called $.selectmenu() after ko.applyBindings() - as seen here: http://jsfiddle.net/aib42/xtz5B/
If you are dynamically adding options to the select menu, then refreshing the select menu can be helpful.
$('#show').selectmenu();
$('#show').selectmenu('refresh');