Hi Stephen,
yes I mailed you :-). I have used User just for example and my form is
more complicated. Let say a UserObject have one FamilyObject and this
FamilyObject have one or two ParentsObjects. So in UserForm is
embedded FamilyForm with embedded FamilyForms (something like this -
three levels of embedding)
I have a solution , but I'm not sure if it is the best one.
It is easy to unset an embedded form for the form class itself:
unset($this->embeddedForms('formName');
but because it is private property it is not possible from outside the
form.
I have created a new form class which extends the base sfForm and this
class adds one public method - removeEmbedded($name).
Now I can use:
$embedded = $form->getEmbeddedForms();
$embedded['relations']->removeEmbedded($name);
I do this in updateObject() because it is called after the form is
validated and everything is o.k.
If I do this in bind() method and the form is not valid it will not be
shown properly .
On Feb 15, 4:46 pm, jukea <[email protected]> wrote:
> Hi patter,
>
> What I'd do is unset the embedded form as if ot was any other field.
>
> if($postedValues[..insert your input name...]=='')
> unset($subForm['embededFormName'])
>
> Do this from anywhere before you bind the data. You could also
> override the bind method in your form, unset the form there, and call
> the parent method.
>
> Julien
>
> On Feb 11, 11:06 am, patter <[email protected]> wrote:
>
> > Hello,
>
> > I have a 1:n relation: User have two phone numbers (well my real use
> > case is a bit complicated :-) ).
>
> > In my UserForm::configure() I have something like this:
>
> > $p1 = $this->object['phones'][0] = new Phone();
> > $p2 = $this->object['phones'][1] = new Phone();
>
> > $subForm = new sfForm();
> > $subForm->embedForm(0, new PhoneForm($p1 );
> > $subForm->embedForm(1, new PhoneForm($p2));
>
> > $this->embedForm('phones', $subForm);
>
> > This works perfect. I can add a new User with 2 phones.
>
> > The problem is that if the user doesn't provide information for second
> > phone I should not insert a blank record (in fact I can't because of
> > not null fields).
>
> > I have read a lot of articles but I'm not able to find solution yet.
>
> > I think that I have to use UpdateObject() method to remove unwanted
> > relation, but if this is the better solution ?
>
> > I use Doctrine :-)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---