Development

#305 ([PATCH]Unable to update boolean values in admin interface)

You must first sign up to be able to contribute.

Ticket #305 (closed defect: worksforme)

Opened 3 years ago

Last modified 5 months ago

[PATCH]Unable to update boolean values in admin interface

Reported by: Jan.Blaha@unet.cz Assigned to:
Priority: major Milestone:
Component: generator Version: 1.0.0
Keywords: admin boolean Cc: l2k <symfony-trac@cny.de>
Qualification: Unreviewed

Description

Boolean type is represented by checkbox. In the auto created actions class is method updateModelFromRequest() that handles setting object attributes according to values in post request.

Following bits serve the boolean type updates:

if (isset($modelactive?)) {

$this->model->setActive(isset($modelactive?) ? $modelactive? : 0);

}

The problem is that when the checkbox is unchecked, there is no request parameter 'active', the isset condition is not met and setActive() does not take place.

The solution is to omit the if(isset($modelactive?)) condition.

Attachments

actions.class.patch (1.3 kB) - added by Jan.Blaha@unet.cz on 03/13/06 11:51:22.
actions.class.2.patch (1.3 kB) - added by Jan.Blaha@unet.cz on 03/13/06 12:30:10.
Shame on me for using short open tags.
checkbox.patch (0.8 kB) - added by sebastien.estienne@gmail.com on 04/21/06 18:05:57.
this is another patch that apply cleanly to the last revision in subversion
checkbox2.patch (0.9 kB) - added by sebastien.estienne@gmail.com on 04/21/06 18:06:49.
this is another patch that apply cleanly to the last revision in subversion

Change History

03/13/06 11:51:22 changed by Jan.Blaha@unet.cz

  • attachment actions.class.patch added.

03/13/06 12:30:10 changed by Jan.Blaha@unet.cz

  • attachment actions.class.2.patch added.

Shame on me for using short open tags.

03/24/06 18:41:15 changed by l2k <symfony-trac@cny.de>

  • cc set to l2k <symfony-trac@cny.de>.

#334 has been marked duplicate of this ticket.


Another note: Why do we need the isset()-conditions in updateXXXFromRequest() at all? As far as I can see, we only process the fields that are shown in the edit form anyway. (Which is a good thing, of course)

03/24/06 18:54:39 changed by anonymous

  • summary changed from Unable to update boolean values in admin interface to [PATCH]Unable to update boolean values in admin interface.

04/10/06 11:13:24 changed by fabien

  • milestone set to 0.6.3.

04/21/06 18:05:57 changed by sebastien.estienne@gmail.com

  • attachment checkbox.patch added.

this is another patch that apply cleanly to the last revision in subversion

04/21/06 18:06:49 changed by sebastien.estienne@gmail.com

  • attachment checkbox2.patch added.

this is another patch that apply cleanly to the last revision in subversion

04/26/06 13:42:45 changed by MartOn

Hello This patch will only work on boolean datatypes. Boolean datatypes are some times also TINYINT (CREOLE makes them tinyint). Then I can just override the type in the generated.yml file.

If I do that, this patch will not work :-(

/MartOn

04/26/06 14:44:00 changed by MartOn

Shouldn't this if statement check for the $input_type == 'checkbox_tag' instead of CREOLE::BOOLEAN?

/MartOn

04/26/06 15:59:24 changed by MartOn

  • version changed from 0.6.1 to 0.7.X.

I had to add this into the if statements:

<?php elseif (($input_type != 'checkbox_tag') && ($type != CreoleTypes::BOOLEAN)): ?>

This works to remove generated code

<?php elseif (($input_type == 'checkbox_tag') || ($type == CreoleTypes::BOOLEAN)): ?>

This one to genererate code for this instance.

I would recommend somebody with deeper knowledge to other ways to overriding tags, take a look at this to verify.

/MartOn

05/03/06 21:08:22 changed by l2k <symfony-trac@cny.de>

#500 has been marked duplicate of this bug

05/15/06 12:45:40 changed by fabien

  • status changed from new to closed.
  • resolution set to fixed.

in r1368.

06/01/07 17:29:51 changed by Luigino.Bracci

  • status changed from closed to reopened.
  • resolution deleted.
  • version changed from 0.7.X to 1.0.0.
  • component set to generator.
  • milestone deleted.

Hi,

I'm using Symfony 1.0.0, and I still have problems with the admin generator when I'm using boolean fields with a checkbox in the generator: sometimes, their current value don't get shown in the edit form accurately (in the database, when the boolean value is set to "true", it doesn't appears checked in the form when I want to edit that record).

The problem appears to be in the autogenerated method "updateXXXXFromRequest()" in actions.class.php (see here):

Line 269:

$this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName () ?>(isset($<?php echo $this-> getSingularName() ?>['<?php echo $name ?> ']) ? $<?php echo $this->getSingularName () ?>['<?php echo $name ?>'] : 0);

It asks if there is a value coming from the form. If true, it assigns that value to the class, but if false, it assigns "0" to the class, ignoring their previous value, even if it was "1".

This could be fixed if the line 269 is changed to:

Line 269:

$this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>(isset($<?php echo $this->getSingularName() ?>['<?php echo $name ?>']) ? $<?php echo $this->getSingularName() ?>['<?php echo $name ?>'] : $this-><?php echo $this->getSingularName() ?>->get<?php echo $column->getPhpName() ?>());

06/23/08 05:14:47 changed by dwhittle

  • status changed from reopened to closed.
  • resolution set to worksforme.
  • qualification set to Unreviewed.
  • milestone set to 1.0.17.

Problem appears to be solved in 1.1.

06/23/08 08:52:11 changed by fabien

  • milestone deleted.