how to create dropdown hint in cakePHP 3 but still able to add own - cakephp-3.0

how to create dropdown hint in cakePHP 3 but still able to add my own string?
I know how to create dropdown field with options:
$this->Form->control('category',array('options' => $categories));
In this I cannot add my new value to field. Is it possible to also have dropdown/combobox/hint and able to add new value?
Thank you for advise.

you have to use javascript library for hint in your CTP file
$this->Form->control('category',array(class=>"select2" 'options' => $categories));
in your template file add js library
and below code
$(document).ready(function() {
$(".select2").select2();
});

Related

How to filter null values with Kartik grid and select2 filter?

I'm trying to add a custom option to my select2 filter (kartik grid). This option is meant to select all rows where something_id=null. It's a simple crud generated grid, modified to use kartik grid and select2 filter instead of yii2 default grid/filter.
I tried doing this in my table2_id column:
'filter' => [null => 'Nothing'] + Arrayhelper::map(Something::find()->orderBy('id)->asArray()->all(), 'id', 'thing')
But this new "null" option is not showing in the menu. I assume for select2 null just mean no filter and select2 just shows the placeholder for that. I can't find any option in select2 documentation to modify this behavior. The generated html for this option is:
<option value="" selected="" data-select2-id="5">Nothing</option>
But the css has the property visibility:hidden;. So I tried using:
'filter' => [0 => 'Nothing'] + Arrayhelper::map(Something::find()->orderBy('id)->asArray()->all(), 'id', 'thing')
But I can't manage to properly translate 'something_id'=>0 into a 'something_id'=>null condition neither in the controller or search model. Tried many things but everything failed at some point and I don't think my code deserves to be posted here, also I don't keep a copy of every failed piece of code so I'd like to ask what is the correct way of doing this from scratch. Thank you.
Well, my answer got deleted because I made a joke. Here is the very very serious version of my answer.
// WatheverSearch.php
if ( $this->something_id === '0' ) {
$query->andWhere(['something_id' => null]);
}else{
$query->andFilterWhere(['something' => $this->something]);
}

Kartik Gridview conflict with my templates menu

I have a template that i was using for my project.
Look at the picture below:
This is when i am not using the kartikGrid. the dropdown menu running as well as the template want.
look at the image below:
this is when i use kartik, the dropdown menu not running anymore.
can some body tell me why it happen.
The template using different bootsrap version with kartik.
thaks.
Hope some body help me.
Imaginaroom, that did the trick for me thank you.
My top menu wasn't responding (direct link, or drop down menu) after kartik was used. I added an id to my menu widget and it did the trick.
echo Nav::widget([
'id' => 'topMenuID',
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
Manually assign different ids to all widgets, so there won't be any conflicts.
If you don't assign ids to widgets, yii gives them one automatically, but the problem occures when loading data with ajax or pjax, then Yii cannot know which ids are already used in the page.
Every widget in Yii2 has a property 'id' that you can assign in configuration array when calling a widget.
Add this code in layout or page that has problem:
$this->registerJs( "$(document).ready(function() { $('.dropdown-toggle').dropdown(); });", View::POS_END, 'ecommerceProductJs' );

formHelper type time : avoiding the annoying dropdown select input?

When i use the cakePHP form helper for a type 'time' field, it automatically generates a dropdown select input and not an easy&easy html5 type time keyboard input like this
Anyone has a quick solution to this ? (preferably without any javascript)
thanks !
FYI, finally i used a jQuery timepicker, that's working fine ! find it here
And after importing the css and js through cakePHP, it's very easy to use.
For example:
With an form element like this (note the type => text)
echo $this->Form->input('time', array(
'type'=>'text',
'label'=>'RĂ©el',
'div'=> array(
'class'=>'two columns')
));
you just call it with
<script>
$('#TimeID').timepicker();
</script>
Just lock the type by manually adding it.
So if you want to use a text field for JS snippets:
echo $this->Form->input('time', array('type' => 'text'));
You can also make it anything else (manually).
For "time" you can try
echo $this->Form->input('time', array('type' => 'time'));
Don't forget to adjust your data form input if necessary.
But careful with HTML5 stuff. This is not suitable for all browsers and therefore can lead to problems in some.

Angular UI select2 directive - updating the model programmatically not reflected on the widget

I'm trying to update select2 model programmatically and for the view to refresh but it doesn't seem to work.
Here's a sample plunker forked from the Angular UI project: http://plnkr.co/edit/kQROgr?p=preview
I tried adding initSelection() accroding to select2 docs (http://ivaynberg.github.com/select2/ "Reacting to external value changes"), but that didn't work. I also tried with select2 3.3.2 and that didn't solve it either.
There are two issues:
1) Click "Update-Model", the model updates but it doesn't add a tag to the select2 widget. Also
2) Click "Update-Model" and then use select2 to pick a second tag, the first tag added by "Update-Model" disappears.
I know the question is a bit old but hey... I found it and didn't know the answer.
I managed to do what I wanted by setting up the model and then recalling initSelection() on the select2Options config
So my config was like so:
$scope.select2Options = {
allowClear: true
minimumInputLength: 3
quietMillis: 1000
initSelection: ->
$scope.property
query: (query)->
Properties.query({q: query.term}, (response)->
data = {results: processData(response['properties'])}
query.callback(data)
)
processData = (data)->
results = []
angular.forEach(data, (item, index)->
results.push(item)
)
return results
}
I then had my modal return the newly created object like so:
modalInstance.result.then((result)->
$scope.property = result
$scope.select2Options.initSelection()
)
Basically once it had updated the model I had to manually reinitialize the select2 widget. I think this could be handled with a $scope.$watch if you really wanted to but that would probably be a waste unless you have the property being updated from a few places or something.

Update panel in asp.net

I am using two update panel..in nested way.. can i use like this and also
in my project im using clientscript.RegisterScript along with update panel , its not giving any error but , my pop up is not being displayed when i click one item on grid. the pop up is in update panel which is inside (nested)..
can anyone help ???
Thank you
RegisterScript may not work well with updatepanel. use PageRequestManager.add_endRequest method to hook-up client script in this scenario.
if (window.Sys){
var prmx = window.Sys.WebForms.PageRequestManager.getInstance();
prmx.add_endRequest(function() {
alert('insert your code here...');
});
}
also make sure there is no javascript erros during page load.