On 1/13/11 8:01 PM, JYeko wrote:
>
> Hi,
>
> I'm trying to create a validator that will check to determine if the value
> entered for a particular field is duplicated in another object. I created a
> validator which check for duplicates. This validator fires when the user
> attempts to move off the field and properly determines if the entered value
> is a duplicate.
>
> However, when the user presses the Save button, the validator fires three
> more times and the final two times appear to be after the object has been
> saved, so the validator finds the newly inserted object as a duplicate (even
> though it has already been saved correctly).
>
> Is there any way to have the validator not check for those subsequent calls.
> I cannot find any difference in the inforamtion available to the validator
> to just return and ignore the validation.
IIRC the multiple validations are due to
(i) using portal factory, meaning the object gets copied
to its final place only after hitting 'save' for the first time.
The adding involved here triggers another round of validation.
(ii) 'validate integrity' meaning that not only are the
individual fields validated as they are entered but also
later during the process when all data has been entered.
Now, (i) you can detect by checking for the '_creationflag'
(or similar) but I'm not aware that you can detect whether
you are in (ii)
I'd recommend that you handle this by introducing a custom
flag e.g., by assigning some attribute to the instance on
first validation and check for it thereafter.
The instance in question can be obtained from the keyword
arguments passed to the validator.
HTH
Raphael
>
> Any ideas would be greatly appreciated.
>
> Thanks.
>
> John
|