Skip to content

Commit

Permalink
Placeholder Text setting for Email and URL fields
Browse files Browse the repository at this point in the history
Resolves #3397
  • Loading branch information
brandonkelly committed Oct 25, 2018
1 parent c017661 commit 581bda9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Added
- Email and URL fields now have “Placeholder Text” settings. ([#3397](https://github.com/craftcms/cms/issues/3397))

### Fixed
- Fixed a bug where the `ContentBehaviour` and `ElementQueryBehavior` classes could be missing some field properties. ([#3400](https://github.com/craftcms/cms/issues/3400))
- Fixed a bug where some fields within Matrix fields could lose their values after enabling the “Manage blocks on a per-site basis” setting. ([verbb/super-table/203](https://github.com/verbb/super-table/issues/203))
Expand Down
26 changes: 26 additions & 0 deletions src/fields/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public static function displayName(): string
return Craft::t('app', 'Email');
}

// Properties
// =========================================================================

/**
* @var string|null The input’s placeholder text
*/
public $placeholder;

// Public Methods
// =========================================================================

Expand All @@ -44,6 +52,23 @@ public function getContentColumnType(): string
return Schema::TYPE_STRING;
}

/**
* @inheritdoc
*/
public function getSettingsHtml()
{
return Craft::$app->getView()->renderTemplateMacro('_includes/forms', 'textField', [
[
'label' => Craft::t('app', 'Placeholder Text'),
'instructions' => Craft::t('app', 'The text that will be shown if the field doesn’t have a value.'),
'id' => 'placeholder',
'name' => 'placeholder',
'value' => $this->placeholder,
'errors' => $this->getErrors('placeholder'),
]
]);
}

/**
* @inheritdoc
*/
Expand All @@ -53,6 +78,7 @@ public function getInputHtml($value, ElementInterface $element = null): string
'type' => 'email',
'id' => $this->handle,
'name' => $this->handle,
'placeholder' => Craft::t('site', $this->placeholder),
'value' => $value,
]);
}
Expand Down
26 changes: 26 additions & 0 deletions src/fields/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public static function displayName(): string
return Craft::t('app', 'URL');
}

// Properties
// =========================================================================

/**
* @var string|null The input’s placeholder text
*/
public $placeholder;

// Public Methods
// =========================================================================

Expand All @@ -45,6 +53,23 @@ public function getContentColumnType(): string
return Schema::TYPE_STRING;
}

/**
* @inheritdoc
*/
public function getSettingsHtml()
{
return Craft::$app->getView()->renderTemplateMacro('_includes/forms', 'textField', [
[
'label' => Craft::t('app', 'Placeholder Text'),
'instructions' => Craft::t('app', 'The text that will be shown if the field doesn’t have a value.'),
'id' => 'placeholder',
'name' => 'placeholder',
'value' => $this->placeholder,
'errors' => $this->getErrors('placeholder'),
]
]);
}

/**
* @inheritdoc
*/
Expand All @@ -54,6 +79,7 @@ public function getInputHtml($value, ElementInterface $element = null): string
'type' => 'url',
'id' => $this->handle,
'name' => $this->handle,
'placeholder' => Craft::t('site', $this->placeholder),
'value' => $value,
]);
}
Expand Down

0 comments on commit 581bda9

Please sign in to comment.