Skip to content

Commit

Permalink
fix(field): string check over integer check
Browse files Browse the repository at this point in the history
  • Loading branch information
michtio committed Feb 14, 2022
1 parent d7ee8f4 commit 194deaf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.1.0] - 2022-02-14

### Fixed
- Fixed an issue that prevented the field from saving.

## [1.0.7] - 2020-05-28
- Began migrating plugin to Hybrid Interactive

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hybridinteractive/craft-width-fieldtype",
"description": "Let users choose from predefined widths",
"type": "craft-plugin",
"version": "1.0.7",
"version": "1.1.0",
"keywords": [
"craft",
"cms",
Expand All @@ -22,7 +22,7 @@
}
],
"require": {
"craftcms/cms": "^3.0.0"
"craftcms/cms": "^3.7.0"
},
"repositories": [
{
Expand Down
12 changes: 5 additions & 7 deletions src/fields/Width.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,11 @@ public static function displayName(): string
*
* @return array
*/
public function rules()
protected function defineRules(): array
{
$rules = parent::rules();
$rules = array_merge($rules, [
['options', 'validateOptions'],
['default', 'string'],
]);
$rules = parent::defineRules();
$rules[] = ['options', 'validateOptions'];
$rules[] = ['default', 'string'];

return $rules;
}
Expand All @@ -109,7 +107,7 @@ public function validateOptions($attribute)
$this->addError($attribute, Craft::t('width-fieldtype', 'Invalid key in $options'));
}

if ($value != 0 && $value != 1) {
if ($value != '' && $value != '1') {
$this->addError($attribute, Craft::t('width-fieldtype', 'Invalid value for $options[{key}].', [
'{key}' => $key,
]));
Expand Down

0 comments on commit 194deaf

Please sign in to comment.