Hi, Am 04.06.2009 um 21:40 schrieb Ascii King:
This Validator references a bit of code (validator_unique_url) that presumably calls the database to check to see if the value is unique. Would someone be able to show what this code would actually look like? I have the rest of the validator example from this thread.Then in MyApp::Schema::ResultSet::Urls, use base qw/MyApp::Schema::Base::ResultSet/; sub validator_unique_url { my $value = shift; .... how do I get at the DB? }
I recently did almost the same and it works well. My relevant part of the form looks like this:
- type: Text name: login label: Login constraints: - Required - type: Callback callback: 'DemoApp::Controller::Login::login_check' message: Already in use filters: - TrimEdgesmy callback-sub is like that -- you can obtain the resultset object using your Application class name. DB is my Schema, Person my table.
sub login_check :Private { my $value = shift; my $result = DemoApp->model('DB::Person') ->search({login => $value}) ->single(); return $result ? 0 : 1; }if you look into HTML::FormFu::Validator::Callback, you can see that the validator coderef is called with the entered value only.
Also, in the following sub, what would be an example of a context? Would it be 'MyApp::Schema' or 'MyApp::Schema::TableName'?
sub validate_value { my ( $self, $value, $params ) = @_; my $c = $self->form->stash->{context}; return $c->model('DBIC::Urls')->validator_unique_url($value); }
Regards, Wolfgang Kinkeldei -- ' /\_/\ ' .print[split??,"".(($/=q|Cms)+-03467:;<=|)=~tr!C-z -B! -z!)x '( o.o )' .$/]->[hex]foreach split qr<>,qq+1ecd039ad65b025b8063475b+|| ' > ^ < ' .q<!-- Wolfgang Kinkeldei - mailto:wolfg...@kinkeldei.de -->
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ HTML-FormFu mailing list HTML-FormFu@lists.scsys.co.uk http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu