0

私はHTML::FormHandlerを使用していますが、コードを繰り返さないように、そのサブクラス化機能を利用したいと考えています。現在、私は2つのフォームを持っています:

myapp::Form::Account::Base
myapp::Form::Account::Register

myapp::Form::Account::Registerから継承しmyapp::Form::Account::Baseます。myapp::Form::Account::Base次のように定義された電子メール フィールドがあります。

has_field 'email' => (
    label            => 'Email',
    type             => 'Text',
    apply            => [ Email ],
    element_class    => [qw/email/],
    required         => 1,
    unique           => 1,
    element_attr => {autocomplete=>"off"}, #for register page
);

ではmyapp::Form::Account::Register、まったく同じ定義済みの電子メール フィールドが必要ですが、それにクラス「uniqueemail」を追加したいと考えています。ただし、これを行うたびに:

has_field 'email' => (
    element_class    => [qw/uniqueemail/],
);

ではmyapp::Form::Account::Register、親フォームの電子メール フィールドの定義を完全に上書きし、新しいものを作成します。親のフォームフィールドをサブクラス化するか、それに追加するだけですか、それとも必要な変更を取得するためにメールフィールドを再定義する必要がありますか? ありがとう!

4

2 に答える 2

2

フィールド名の前に「+」を使用して、親定義をオーバーライドするフィールド定義を指定できます。

has_field '+email' => (
    element_class    => [qw/uniqueemail/],
);
于 2013-02-05T17:19:32.127 に答える
1

You could make a custom field type. Look at the definition of HTML::FormHandler::Field::Text or HTML::FormHandler::Field::Email:

Then make your email type with the defaults you want. Then in myapp::Form::Account::Base your email field would look something like this:

has_field 'email' => (
    type             => '+myapp::Form::Account::CustomEmail'
);

then in myapp::Form::Account::Register:

has_field 'email' => (
    type             => '+myapp::Form::Account::CustomEmail',
    element_class    => [qw/uniqueemail/],
);
于 2013-02-04T13:26:59.403 に答える