cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Form element clear does not work for existing model and validity check

Open dunst0 opened this issue 8 years ago • 3 comments

Expected and Actual Behavior

When an entity is given to the form with the constructor and this form is validated, clear doesn't seems to work. Expected behavior is that value is empty. Actual behavior the old value is still set. If instead null is passed clear does it expected work.

$form = new MyForm(new SomeModel());
$form->isValid($this->request->getPost());
error_log(" {$form->render('foo')} ");
$form->get('foo')->clear();
error_log(" {$form->render('foo')} ");
[Wed Apr 18 22:00:59 2018]  <input type="text" id="foo" name="foo" value="12345" />
[Wed Apr 18 22:00:59 2018]  <input type="text" id="foo" name="foo" value="12345" />

This works:

$form = new MyForm(null);
$form->isValid($this->request->getPost());
error_log(" {$form->render('foo')} ");
$form->get('foo')->clear();
error_log(" {$form->render('foo')} ");
[Wed Apr 18 22:00:59 2018]  <input type="text" id="foo" name="foo" value="12345" />
[Wed Apr 18 22:00:59 2018]  <input type="text" id="foo" name="foo"  />

Details

  • Phalcon version: (php --ri phalcon)
$ php --ri phalcon

phalcon


Web framework delivered as a C-extension for PHP
phalcon => enabled
Author => Phalcon Team and contributors
Version => 3.3.2
Build Date => Apr 18 2018 21:17:49
Powered by Zephir => Version 0.10.7-2917ebe8ae

Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.events => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.orm.column_renaming => On => On
phalcon.orm.not_null_validations => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.enable_literals => On => On
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.ignore_unknown_columns => Off => Off
phalcon.orm.update_snapshot_on_save => On => On
phalcon.orm.disable_assign_setters => Off => Off
  • PHP Version: (php -v)
$ php -v
PHP 7.2.4 (cli) (built: Apr 12 2018 02:49:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.4, Copyright (c) 1999-2018, by Zend Technologies
  • Operating System: MacOS
  • Installation type: Compiling from source
  • Zephir version (if any):
  • Server: php build in

dunst0 avatar Apr 18 '18 20:04 dunst0

Just to clarify the expected behavior is expected when the entity doesn't have values set or the form element doesn't h have an counterpart in the entity

dunst0 avatar Apr 24 '18 16:04 dunst0

@dunst0 So that I understand this correctly:

  • Entity: name, id

Form Elements: name, id, address, status

clear() with an entity should clear address and status or all?

niden avatar May 15 '19 21:05 niden

Closing this issue - no reply for this NRF/Bug. Can reopen later on if need be.

niden avatar Jun 16 '19 20:06 niden