Kartik Editable Checkbox does not show default value as checked - checkbox

I am using Kartik/Editable of latest version.
Implemented a checkbox popup which works, but it does not show the default value as checked/unchecked.
Example:
echo Editable::widget([
'name' => 'test',
'value' => 1,
'asPopover' => false,
'inputType'=>Editable::INPUT_CHECKBOX,
]);
This will show a popover where the checkbox is not checked at all, but it should be as value = 1.
According to Kartiks documentation, the value should be an integer, not boolean.
Am I missing something? Or is this by design?

You should add 'options' => ['checked' => true,], for checkbox checked.
Editable::widget([
'name' => 'test',
'value' => 1,
'asPopover' => false,
'options' => ['checked' => true,],
'inputType' => Editable::INPUT_CHECKBOX,
]);

Related

How to set the enable and disable value to table column switch button in react js

Im using class component in my application.
I want to set the value to the table column button. and i fetch the value from backend
it was an array response. Array values auto mapped by my table column key.
Ex: This was my table column and it was auto mapped by fetch response name. fetch response name
is "description".
{
title: 'Description',
dataIndex: 'description',
key: 'description',
sorter: true
},
But problem is how auto mapped to the response name to switch button I try but I can't.
My Switch column:-
{
title: 'Action',
dataIndex: 'enabled',
key: 'enabled',
render: (text: any, record: any) => (
<div>
<Tooltip title="Enable / Disable" color={'#d31145'}>
<Switch autoFocus checkedChildren="Enable" unCheckedChildren="Disable" className={'customswitch'} onChange={checked => this.changeSwitch(checked,record.proId)}/>
</Tooltip>
</div>
),
}
I need to know how to set the fetch value to switch button in react class component.
I fetch All data from using this code.
fetch = (params: any = {}) => {
let providerConfigureDto: ProviderConfigureDto = {...this.state.providerConfigureDto};
this.setState({isLoading: true});
providerConfigureService.getAllProviders(providerConfigureDto).then(res => {
console.log(res.data.content)
const pagination: any = {...this.state.pagination};
pagination.total = res.data.total;
this.setState({
isLoading: false,
total: res.data.totalElements,
providerConfigures: res.data.content,
providerConfigureDto: providerConfigureDto,
pagination
});
})
providerConfigureDto.page = 0
};
ProviderConfigureDto has only sorter option and pagble option only.
I fetch from array from back end and i create a array in state. then i set the array to table datasouce
Like this :-
providerConfigures:Array<any>,
That's all please help me for that.

How to get which button is clicked using 'useForm' from 'react-hook-form'

How to get status value as "APPROVED" when 'APPROVE' button is clicked, and "DENIED" when 'DECLINE' is clicked. Thank you
After searching, i din't get any reference. So, I added onClick to both buttons and passing Approve,Declined values from that on click function to
onClick={() => clickedOnSubmit('Approve')}
onClick={() => clickedOnSubmit('Decline')}
clickedOnSubmit = (type: any) => {setSubmitType(type) }.
here i'm setting the state value. on onSubmit i'm using that submitType. This is working in my case.
onClick={() => form.setValue('name', 'value', { shouldValidate: true })}

How to disable the button once clicked in antd table?

Getting the table values through props. The claim update function is working fine, but the record still there. once I refresh or select another tab only after that the claimed record will be removed.
{
title: 'Action',
dataIndex: 'action',
render: (text, record) =>
<Button class="claimBom-btn" onClick={(e) => this.handleClaim(e,text, record)} ><Icon type="plus-circle" />Claim</Button>
}
This the button call for all record in the table
Just pass along the button state in the datasource.
When it is clicked mutate the datasource.
const [datasource, setDatasource] = useState([
{
disabled: false,
// others properties
}
]);
// On button click find the data and change disabled property
const onClick = (id) => {
const source = datasource.find(source => source.id === id);
source.disabled = true;
setDatasource(datasource);
}
{
title: 'Action',
dataIndex: 'action',
render: (text, record) =>
<Button disabled={text.disabled} class="claimBom-btn" onClick={(e) => this.handleClaim(e,text, record)} ><Icon type="plus-circle" />Claim</Button>
}
You can simply pass the disabled prop to the button accordingly. When calling this.handleClaim, set a state of which button should be disabled while handling, and pass that as a disabled prop to the button.

CakePHP Custom route calling wrong action

I have the following code in routes.php:
Router::connect('/c/details/:id/:slug',
array('controller' => 'cars'),
array('pass' => array('id', 'slug'))
);
If I try to access http://domain.com/c/details/123/abc, it works. However, if I remove abc (ie the slug), CakePHP tries to access the action 123 (which is the id, not the action).
Error: The action 123 is not defined in controller CarsController
If I use /c/details/:id/:slug/:action/*, which was what I had before upgrading from 1.2 (yeah, pretty old) to 2.2.1 and it was working fine, CakePHP also tries to access action 123 whether I have a slug or not.
URLs without slugs always worked before upgrading CakePHP and with the code I have in the controller, if there was no slug in the URL, it would redirect to the right URL.
Edit: I just checked and it seems that when I don't provide with a slug, the whole thing is shifted. c is ignored, details becomes the controller and 123becomes the action.
[request] => CakeRequest Object
(
[params] => Array
(
[plugin] =>
[controller] => details
[action] => 123
[named] => Array()
[pass] => Array()
[isAjax] =>
)
When the correct would be, and which is what I get if I provide with a slug:
[request] => CakeRequest Object
(
[params] => Array
(
[plugin] =>
[controller] => cars
[action] => index
[named] => Array()
[pass] => Array
(
[0] => 123
[1] => abc
)
[id] => 123
[slug] => abc
[isAjax] =>
)
Any idea what may be causing this issue now?
You may need 2 routes if you want the slug to be optional (not sure). In any case, add the action key to each route as well.
Router::connect('/c/details/:id',
array('controller' => 'cars', 'action' => 'details'),
array('pass' => array('id'))
);
Router::connect('/c/details/:id/:slug',
array('controller' => 'cars', 'action' => 'details'),
array('pass' => array('id', 'slug'))
);

CakePHP model relations, how to avoid unnecessary data?

I'm learning CakePHP, thus I'm making a simple blog in order to learn basic functionality, this blog will have tables holding posts, users, users activation codes and taxonomy along with taxonomy relationships between posts and tags.
Ok, the thing now is, I've managed to set everything up properly and every time I fetch a post, it returns a lot of data:
Array
(
[Post] => Array
(
[post_id] => 1
[post_title] => Test 1
[post_nice_name] => test-1
[post_author] => 1
[post_content] => I'm testing this piece of crap.
[post_creation_time] => 2011-11-13 22:50:05
[post_last_modification] => 2011-11-13 22:50:05
[post_allow_comments] => 1
[post_allow_trackback] => 1
[post_display] => 1
)
[User] => Array
(
[user_id] => 1
[user_email] => XX#XXXXXXXXXXx.XX.XX
[user_password] => XXXXXXXXXXXXXXXXXX
[user_creation_time] => 2011-11-13 10:48:10
[user_last_login] => 2011-11-13 22:49:21
[user_birthday] => 1993-08-24 03:00:00
)
[TaxonomyTags] => Array
(
[0] => Array
(
[tag_id] => 1
[tag_name] => test1
[tag_description] => This tag is a test
[PostsTaxonomyTag] => Array
(
[relation_id] => 1
[post_id] => 1
[taxonomy_tag_id] => 1
)
)
[1] => Array
(
[tag_id] => 2
[tag_name] => test2
[tag_description] => This tag is just another test.
[PostsTaxonomyTag] => Array
(
[relation_id] => 2
[post_id] => 1
[taxonomy_tag_id] => 2
)
)
)
)
This much data is really unnecessary: I don't need the PostsTaxonomyTag array for every tag, nor do I need that much of the user's information, I don't even need some of the post's information!. So I wanted to know if there's any way to filter this information before it is passed on to the view.
You can unbind models befor a find function to prevent unneeded data
$this->Model->unbind(array('hasMany' => array('assocModel')));
I prefer to use the containable behavior for most models which forces you to state the relationships you need at find though. Mcheck the docs about that behavior.
$this->Model->find(
'all',
array(
'conditions' => array(
//set conditions
),
'contain' => array(
'Model2',
'model3'
)
)
);
You can set conditions, order, etc. in the containable set making it powerful for getting exactly the data you need.
... or you can simple use 'recursive' => -1 in options for find.

Resources