Using Doctrine in symfony 1.4 I have several boolean columns defined (stored as a tinyint in mySQL). The checkbox widgets are always rendering as checked, even when the returned value is '0'. It seems related to this ticket.
Is this a common problem? Is there a workaround?
I can get it working by changing line 70 in sfWidgetFormInputCheckbox to:
if (null !== $value && $value !== false && $value !== 0)
but I'd rather not alter core symfony files.
Another hack to resolve this bug without changing the Symfony classes is to set the default value for the field in the database to 0 (unchecked):
chk_field: { type: boolean, default: 0 }
And in set the widget in the Form.class as follows:
$this->setDefault('chk_field', $this->getOption('default'));
This should display the 'chk_field' field as 'unchecked' in your form
Symfony unresolved bug, see http://www.devexp.eu/2009/04/23/sfwidgetforminputcheckbox-unchecked-bug/
Your database returns a 0 for a unchecked box but Symfony renders it as checked.
You can patch yourself by editing symfony/lib/widget/sfwidgetforminputcheckbox.class, line 70 (in version 1.4.6), change:
if (null !== $value && $value !== false)
in
if (null !== $value && $value !== false && $value != 0)
Not sure in what context you're seeing the problem. I can get the following to work fine:
$database_field = '1;0;1;0;1;0;1';
$checked = explode(';', $database_field);
$this->form->getWidget('a_set_of_checkboxes')->setDefault($checked);
... the checkboxes with 1's get checked, 0's not.
I'm using "sfWidgetFormChoice" widgets with the attributes "multiple: true" and "expanded: true" so they're not individual checkbox widgets, but rather a single widget that contains an array of checkboxes/values.
Related
I am using ExtJS 6 (although from what I can tell it applies up to version 7.4 as well) and I have a grid with a booleancolumn xtype. For that boolean column I wanted to use the filter list option. Yes I know there is a boolean filter option however I don't like how it works using a radio button. I wanted to be able to select the Yes or No with checkboxes, however I found that only the option with true as the value worked. Here is my column config:
{
header: 'Active'
, dataIndex: 'inactive'
, xtype: 'booleancolumn'
, trueText: 'No'
, falseText: 'Yes'
, filter:{
type: 'list',
options: [[true,"No"],[false, "Yes"]]
}
}
This didn't work when excluding the 'options' property and letting it get the data from the store either by the way. After looking through the code I discovered that it takes the 'options' config and creates its own Ext.Data.Store using that as the data. See here as a simple example that can be run that will get the same issue:
var teststore = new Ext.data.Store({
fields: [
'id',
'text'
],
data: [[true,"No"],[false, "Yes"]]
});
The problem is that the 'false' boolean value is changed and is replaced with a dynamically created generic id. I discovered the issue lays in the constructor for 'Ext.data.Model' for the following line:
if (!(me.id = id = data[idProperty]) && id !== 0) {
If that line evaluates to true it will replace the id with the generated one. To fix this I just added ' && id !== false' to the end of the if statement and this fixed the issue.
I have not tested this fully, however the logic seems sound and it looks like the same type of issue occurred with the value of '0' hence the ' && id !==0'. Since we are directed here from the sencha forums I wanted to bring this up in case it helps someone.
Since my post already has the answer I will post a better way to do it other than directly changing the Ext code file (whether this is the proper way I may be wrong). Instead, you can create a new js file that will need to be included in your application (you can name it ext-overrides.js). In the new js file you need only type:
Ext.override(Ext.data.Model, {
constructor: function(data, session) {
.....
}
}
You would then copy the constructor function code from your version of the ExtJS code in where the '.....' is (if perchance the constructor function arguments are different you would have to update those as well) and just add the suggested change I made above in the 'question'. A search of the Extjs code for Ext.define('Ext.data.Model' should get you there easily and then just scroll to the constructor function.
I wanted to see if anybody on here has encountered this yet...I'm looking to work with multiple ComboBoxes to Filter data in a Gallery. Currently, I have a search bar (TextInput1.Text) working in conjunction with multiple ComboBoxes (ComboBox1 and ComboBox3) -- which is attached to the Gallery > Items Function :
Gallery> Items = Filter('Table A',
((TextInput1.Text in 'Description') ||
(TextInput1.Text in 'Name - Long') ||
(TextInput1.Text in 'Tags')) &&
('Target Type'.Value exactin ComboBox1.SelectedItems.Result &&
'Target Level'.Value exactin ComboBox3.SelectedItems.Result)
)
PROBLEM
The issue with the ('Target Type'.Value exactin ComboBox1.SelectedItems.Result && 'Target Level'.Value exactin ComboBox3.SelectedItems.Result), part in the function above is that when you apply the && operator in between ComboBox1 and ComboBox2 , none of the data populates on the Gallery unless items are selected on BOTH ComboBoxes. Similarly, when using the || operator it only responds to the MOST RECENTLY selected items in the boxes.
POSSIBLE SOLUTION
In order for multiple ComboBoxes to execute cross-reference functionality(which is essentially what I'm trying to do with multiple boxes), I have to use an IF function that follows the following logic:
IF(more than 1 comboBox is being selected, apply && logic in between ComboBoxes[like shown above], else apply ||)
or
IF( just 1 combobox is being used, apply || logic, else apply &&)
Am I going about this the right way? If so, how would a function look in its entirety when incorporating this?
My purpose is to translate interactively a checkbox action into a couple of values "0001" or "".
I placed this method on a table whose name is Notification.
// BP Deviation Documented
edit NoYesId provenWarranty (boolean _set = false, NoYesId _provenWarranty = NoYes::No)
{
NoYesId provenWarr;
;
// set value
if (_set)
{
if (_provenWarranty)
this.Func_Status = '0001';
else
this.Func_Status = '';
return _provenWarranty;
}
// read value
if (this.Func_Status == '0001')
return NoYes::Yes;
else
return NoYes::No;
}
This method is used by a Checkbox in a Form with this Table as a Datasource.
This method has been cached in the Notification datasource init() method.
Notification_ds.cacheAddMethod(tablemethodstr(Notification, provenWarranty));
My problem is that the Checkbox is constantly flickering, is there a way to avoid that ?
Update
The flickering appears inside the Checkbox design, but without
toggling it between checked or not.
This problem appears even if the Checkbox is connected to a basic
datasource field, not only if connected to an edit method.
It seems that the more fields there are in the datasource, the more
flickering I get.
I'm working with an ExtJS 4 propertygrid that can list three different kinds of items that display when clicked on in another grid. One kind of item has to have a particular field hidden, so that it is't shown but any updates caused by editing other fields aren't affected by potentially missing information.
Attempts of using hidden/isHidden/visible/isVisible, with quoted and unquoted true/false values, haven't worked, and show the ShapeLength field in the propertyGrid.
Is there a "hidden: true" setting within the sourceConfig that I can apply somehow?
Example code:
var lengthDisplayName = '';
if(record.data.Type_ID == 'Circle(s)'){
lengthDisplayName = 'Radius (mm)';
}
if(record.data.Type_ID == 'Triangle(s)'){
lengthDisplayName = 'Side Length (mm)';
}
detailsGrid.sourceConfig['ShapeLength'] = {displayName: lengthDisplayName, type: 'number'};
if(record.data.Item_No == '-1'){
detailsGrid.sourceConfig['ShapeLength'] = {
displayName: lengthDisplayName,
type: 'number'
//, hidden/isVisible/visible value set here
}
};
No there is no hidden property for sourceConfig. But one possibility is to remove the property from the sourceConfig and reinsert it if it should be visible again.
delete detailsGrid.sourceConfig['ShapeLength'];
Was directed to an answer by a colleague - I can getRowClass within the propertyGrid and apply a hidden style on source data for an identifying property and the row name to hide, or else return out:
detailsGrid.getView().getRowClass = function(row) {
if(detailsGrid.source['Item_No'] == '-1' && row.data.name == 'ShapeLength')
return 'x-hidden';
return;
};
Hey guys I've been working on this for a few days now but I can't seem to get it to work :(
Here is the situation.
I have an "edit profile" page.
On that page you can, like the name implies, edit profile information.
for the example here is what I'm trying to do.
Database record:
||-------||----------||-----------||
|| name || surname || email ||
||-------||----------||-----------||
|| Amy || Nuts || an#no.com ||
||-------||----------||-----------||
I have a form that gives the user the ability to enter their own data and change some of the fields.
The form fields all have names that corrospond with the database fields.
<input name="name" ......
<input name="surname" ......
<input name="email" .....
This is all very logical and easy.
The problem that I have is when I submit the form.
I build my website with HTML5 and use placeholders for the form fields.
I do this because it looks nice imo and I can experiment some with it.
When I just want to update the surname, the other fields stay empty.
Codeigniter by default returns a "false" in the case of an empty post item.
Maybe you can see my problem.
When I send the post data to the model and it updates the database record, it will remove the data from the "name" and "email" fields and update the surname.
The array looks like this:
array(
"name" =>
"surname" => NEW
"email" =>
)
After running this through the update function of codeigniter the database record looks like this
||-------||----------||-----------||
|| name || surname || email ||
||-------||----------||-----------||
|| || NEW || ||
||-------||----------||-----------||
what I want to know is, if there is a posibility to let codeigniter ignore the array items that do not have data.
I hope you guys can help out.
I'm at a loss here.
use array_filter($data) to remove any empty fields before sending it to database.
also it looks like you dont validate your data for update ?
can you please show the code in your model to store updates ?
example
$data['name']=$this->input->post('name');
$data['lastname']=$this->input->post('lastname');
$data=array_filter($data); //will remove empty keys
Or
if($this->input->post('name')) $data['name']=$this->input->post('name');
if($this->input->post('lastname')) $data['name']=$this->input->post('lastname');
in all cases you should really always validate your data before submitting it to database;
just a general note:
i would recommend you always have 2 layers of validations;
at controller to validate form (using CI form_validation)
at model to validate DATA (also using CI form_validation)
never trust your controller alone. the best DRY method i use in CI is that in my model
i use variable
models/demo_model.php
public $validate =array(
['field' => 'login','label' => 'lang:user_login','rules' => 'trim|required|min_length[5]|max_length[100]|xss_clean'],
['field' => 'password','label' => 'lang:user_password','rules' => 'trim|required|min_length[5]|max_length[35]|xss_clean']);
function is_valid($data,$mode=null){
if(!$this->validate || empty($data) )return false; //nothing to validate !
$config=array();
//if updating then its normal that some variables will be missing
//so lets apply rules for only data we going to update; to make sure its xss_clean, not exceed database size, trim, etc;;
if($mode = 'update'){
foreach($this->validate as $rule)if( ! empty( $data[ $rule['field'] ] )$config[]=$rule
}else{
$config = $this->validate
}
$this->form_validation->reset_validation();
$this->form_validation->set_data($data); #we are not using $_post;
$this->form_validation->set_rules($config);
return ($this->form_validation->run() === TRUE)
}
now in every database call before you use $this->db->insert; or update; u just use
$this->is_valid($data,'update'); // dont set 2nd param if you are inserting and want all rules to apply;
and this will validate all your requests;
also note that codeigniter form_validation can be used for modifing submitted values also;
for example using trim rule, or md5 rule on password field
well sorry i might hv extended my answer too long, i hope i answered you question.