Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #18894: Not able to add theme option text input #3354

Merged
7 changes: 5 additions & 2 deletions application/views/themeOptions/options_core.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,13 @@
</i> )
</div>
</div>';
} elseif ($attribute['type'] == 'input') {
} elseif ($attribute['type'] == 'text') {
echo '<div class="col-12">
<input type="text" class="form-control selector-text-input selector_text_option_value_field" data-parent="' . $attribute['parent'] . '" id="simple_edit_options_' . $attributeKey . '" name="' . $attributeKey . '" title="' . gT("inherited value:") . ' ' . $sParentOption . '" />
</div>';
} elseif ($attribute['type'] == 'duration') {
echo '<div class="col-12">
<input type="text" class="form-control selector-numerical-input selector_option_value_field selector_radio_childfield" data-parent="' . $attribute['parent'] . '" id="simple_edit_options_' . $attributeKey . '" name="' . $attributeKey . '" title="' . gT("inherited value:") . ' ' . $sParentOption . '" />
<input type="text" class="form-control selector-numerical-input selector_text_option_value_field selector_radio_childfield" data-parent="' . $attribute['parent'] . '" id="simple_edit_options_' . $attributeKey . '" name="' . $attributeKey . '" title="' . gT("inherited value:") . ' ' . $sParentOption . '" />
</div>';
}

Expand Down
23 changes: 21 additions & 2 deletions assets/packages/themeoptions-core/themeoptions-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ var ThemeOptions = function () {

});

globalForm.find('.selector_text_option_value_field').each(function (i, item) {
//disabled items should be inherit or false
if ($(item).prop('disabled')) {
$(item).val((inheritPossible ? 'inherit' : false));
}

optionObject[$(item).attr('name')] = $(item).val();
});

var newOptionObject = $.extend(true, {}, optionObject);
delete newOptionObject.general_inherit;

Expand Down Expand Up @@ -138,7 +147,7 @@ var ThemeOptions = function () {

//Parses the option value for an item
var parseOptionValue = function (item, fallbackValue) {
fallbackValue = fallbackValue || false;
if (fallbackValue == undefined) fallbackValue = false;
// If general inherit, then the value of the dropdown is inherit, else it's the value defined in advanced options
var itemValue = generalInherit() ? 'inherit' : optionObject[$(item).attr('name')];

Expand All @@ -163,6 +172,7 @@ var ThemeOptions = function () {

// Update values in the form to the template options
// selector_option_value_field are the select dropdown (like variations and fonts)
// TODO: This seems to be designed for select fields only, but it is also used for other input types. Should be reviewed.
var prepareSelectField = function () {
globalForm.find('.selector_option_value_field').each(function (i, item) {
var itemValue = parseOptionValue(item);
Expand Down Expand Up @@ -220,6 +230,14 @@ var ThemeOptions = function () {

};

// Update values of 'text' options in the form
var prepareTextField = function () {
globalForm.find('.selector_text_option_value_field').each(function (i, item) {
var itemValue = parseOptionValue(item, "");
$(item).val(itemValue);
});
};

///////////////
// HotSwap methods
// -- These methods connect an input directly to the value in the optionsObject
Expand Down Expand Up @@ -250,7 +268,7 @@ var ThemeOptions = function () {
// hotswapping the fields
var hotSwapFields = function () {

globalForm.find('.selector_option_value_field').on('change', function (evt) {
globalForm.find('.selector_option_value_field, .selector_text_option_value_field').on('change', function (evt) {
updateFieldSettings();
parseNumeric(this);
});
Expand Down Expand Up @@ -450,6 +468,7 @@ var ThemeOptions = function () {
startupGeneralInherit();

prepareSelectField();
prepareTextField();
parseParentSwitchFields();
prepareFontField();
prepareFruityThemeField();
Expand Down