-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1700 from tomudding/fix/text-field-not-required-s…
…ign-ups Add validator to `Text` type sign-up list field
- Loading branch information
Showing
5 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Activity\Form\Element; | ||
|
||
use Laminas\Filter\StringTrim; | ||
use Laminas\Form\Element\Text; | ||
use Laminas\InputFilter\InputProviderInterface; | ||
use Laminas\Validator\NotEmpty; | ||
use Laminas\Validator\ValidatorInterface; | ||
|
||
class ValidatedText extends Text implements InputProviderInterface | ||
{ | ||
protected ?ValidatorInterface $validator = null; | ||
|
||
/** | ||
* Get primary validator. | ||
*/ | ||
protected function getValidator(): ValidatorInterface | ||
{ | ||
if (null === $this->validator) { | ||
$this->validator = new NotEmpty(NotEmpty::STRING); | ||
} | ||
|
||
return $this->validator; | ||
} | ||
|
||
/** | ||
* Provide default input rules for this element | ||
* | ||
* Attaches a not empty validator and a string trim filter. | ||
* | ||
* @inheritDoc | ||
*/ | ||
public function getInputSpecification(): array | ||
{ | ||
$spec = [ | ||
'required' => true, | ||
'filters' => [ | ||
['name' => StringTrim::class], | ||
], | ||
'validators' => [ | ||
$this->getValidator(), | ||
], | ||
]; | ||
|
||
$name = $this->getName(); | ||
if (null !== $name) { | ||
$spec['name'] = $name; | ||
} | ||
|
||
return $spec; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,10 @@ | |
@import 'form'; | ||
} | ||
|
||
.form-signup { | ||
@import 'form'; | ||
} | ||
|
||
.container > section { | ||
padding: 0; | ||
} |