Skip to content

Commit

Permalink
Prefix and Suffix settings for Number fields
Browse files Browse the repository at this point in the history
Resolves #4055
  • Loading branch information
brandonkelly committed Mar 27, 2019
1 parent a06e979 commit e0eebc2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Added
- Added the `verifyEmailSuccessPath` config setting.
- Added the “Prefix” and “Suffix” settings for Number fields. ([#4055](https://github.com/craftcms/cms/issues/4055))
- Added the “Max Length” setting for URL fields. ([#4019](https://github.com/craftcms/cms/issues/4019))
- Added the `devMode` global Twig variable. ([#4038](https://github.com/craftcms/cms/issues/4038))
- Added `craft\config\GeneralConfig::getVerifyEmailSuccessPath()`.
Expand Down
20 changes: 14 additions & 6 deletions src/fields/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ public static function displayName(): string
*/
public $size;

/**
* @var string|null Text that should be displayed before the input
*/
public $prefix;

/**
* @var string|null Text that should be displayed after the input
*/
public $suffix;

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

Expand Down Expand Up @@ -171,12 +181,10 @@ public function getInputHtml($value, ElementInterface $element = null): string
}
}

return '<input type="hidden" name="' . $this->handle . '[locale]" value="' . Craft::$app->language . '">' .
Craft::$app->getView()->renderTemplate('_includes/forms/text', [
'name' => $this->handle . '[value]',
'value' => $value,
'size' => $this->size
]);
return Craft::$app->getView()->renderTemplate('_components/fieldtypes/Number/input', [
'field' => $this,
'value' => $value,
]);
}

/**
Expand Down
22 changes: 22 additions & 0 deletions src/templates/_components/fieldtypes/Number/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% from '_includes/forms' import text %}

<input type="hidden" name="{{ field.handle }}[locale]" value="{{ craft.app.language }}">
<div class="flex">
{% if field.prefix %}
<div>
{{ field.prefix|md(inlineOnly=true)|raw }}
</div>
{% endif %}
<div>
{{ text({
name: field.handle ~ '[value]',
value: value,
size: field.size
}) }}
</div>
{% if field.suffix %}
<div>
{{ field.suffix|md(inlineOnly=true)|raw }}
</div>
{% endif %}
</div>
18 changes: 18 additions & 0 deletions src/templates/_components/fieldtypes/Number/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,21 @@
size: 2,
errors: field.getErrors('size')
}) }}

{{ forms.textField({
label: "Prefix Text"|t('app'),
instructions: "Text that should be shown before the input."|t('app'),
id: 'prefix',
name: 'prefix',
value: field.prefix,
errors: field.getErrors('prefix')
}) }}

{{ forms.textField({
label: "Suffix Text"|t('app'),
instructions: "Text that should be shown after the input."|t('app'),
id: 'suffix',
name: 'suffix',
value: field.suffix,
errors: field.getErrors('suffix')
}) }}

0 comments on commit e0eebc2

Please sign in to comment.