i had exactly the same problem and solved it by removing empty lines
in the beforeFilter() of the controller responsible for saving items.
In my case its very specific you could apppend your logic to make it
more universal.

p.s. im not sure about the following line in your example, because im
not sure if !null is defined in php
if (array_search(!null, $record)) $validRecords[] = $record;
maybe im wrong but i dont think this filters your data correctly.


--- in my app i use:
class InvoicesController extends AppController {
        function beforeFilter() {
                if (!empty($this->data)) {

                        // remove empty forms from data
                        if (isset($this->data['InvoicesItem'])) {
                                $data = array();
                                foreach ($this->data['InvoicesItem'] as $row) {
                                        if (!empty($row['quantity']) || 
!empty($row['price'])) {
                                                $data[] = $row;
                                        }
                                }
                                if (empty($data)) {
                                        unset($this->data['InvoicesItem']);
                                }
                                else {
                                        $this->data['InvoicesItem'] = $data;
                                }
                        }
                }

        }
...
}

On Nov 24, 4:28 pm, Ernesto <e.fanz...@gmail.com> wrote:
> A - i already have a routine that *should* to that... but it isn't
> working properly. here's the code
>
> function beforeValidate() {
>      $validRecords = array();
>      foreach ($this->data as $model => $records) {
>           foreach ($records as $key => $record) {
>                if (is_numeric($key)) {
>                     if (array_search(!null, $record)) $validRecords[]
> = $record;
>                } else break;
>                $this->data[$model] = $validRecords;
>           }
>      }
>      return true;
>
> }
>
> B - my saveAll is already overwritten in AppModel and atm it's working
> ok. i was just asking if it's possible to do that in a Behavior :)
>
> On 23 Nov, 20:52, Marcelo Andrade <mfandr...@gmail.com> wrote:
>
> > On Mon, Nov 23, 2009 at 12:29 PM, Ernesto <e.fanz...@gmail.com> wrote:
> > > (..)
> > > A - user can insert just 2 or 3 rows, it's not necesasry to fill all
> > > the 10 "Item" rows. saveAll tries to save even empty insertions. Blank
> > > rows = validation errors. is there any way to avoid this?
>
> > You'll have to loop $this->data and unset the entries when
> > you get blank fields.
>
> > > B - is it pobbile to create a behavior that forces "validate" =>
> > > "first" to every saveAll call?
>
> > You can override the saveAll method in your AppModel,
> > changing the validate entry in the options to 'first' always.
>
> > Best regards.
>
> > --
> > MARCELO DE F. ANDRADE
> > Belem, PA, Amazonia, Brazil
> > Linux User #221105

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to