Thanks, Wolfgang. That did the trick.
Wolfgang Kinkeldei wrote:
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:
- TrimEdges
my 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
------------------------------------------------------------------------
_______________________________________________
HTML-FormFu mailing list
[email protected]
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
_______________________________________________
HTML-FormFu mailing list
[email protected]
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu