diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs index 2f0b20ba..2238ae98 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs @@ -111,6 +111,18 @@ checked=field.char_counter}} + +
+
+ +
+ +
+ {{textarea + name="field_placeholder" + value=field.placeholder}} +
+
{{/if}} {{#if isUpload}} diff --git a/assets/javascripts/wizard/initializers/custom-wizard.js.es6 b/assets/javascripts/wizard/initializers/custom-wizard.js.es6 index ab7c9146..24102bed 100644 --- a/assets/javascripts/wizard/initializers/custom-wizard.js.es6 +++ b/assets/javascripts/wizard/initializers/custom-wizard.js.es6 @@ -26,7 +26,11 @@ export default { const setDefaultOwner = requirejs("discourse-common/lib/get-owner") .setDefaultOwner; const messageBus = requirejs("message-bus-client").default; - + const getToken = requirejs("wizard/lib/ajax").getToken; + const setEnvironment = requirejs("discourse-common/config/environment") + .setEnvironment; + const isDevelopment = requirejs("discourse-common/config/environment") + .isDevelopment; const container = app.__container__; Discourse.Model = EmberObject.extend(); Discourse.__container__ = container; @@ -89,6 +93,7 @@ export default { const session = container.lookup("session:main"); const setupData = document.getElementById("data-discourse-setup").dataset; session.set("highlightJsPath", setupData.highlightJsPath); + setEnvironment(setupData.environment); Router.reopen({ rootURL: getUrl("/w/"), @@ -107,5 +112,11 @@ export default { }, model() {}, }); + + $.ajaxPrefilter(function (_, __, jqXHR) { + if (isDevelopment()) { + jqXHR.setRequestHeader("X-CSRF-Token", getToken()); + } + }); }, }; diff --git a/assets/javascripts/wizard/templates/components/wizard-composer-editor.hbs b/assets/javascripts/wizard/templates/components/wizard-composer-editor.hbs index 1e7c27df..c4bf1c74 100644 --- a/assets/javascripts/wizard/templates/components/wizard-composer-editor.hbs +++ b/assets/javascripts/wizard/templates/components/wizard-composer-editor.hbs @@ -1,7 +1,7 @@ {{d-editor tabindex=field.tabindex value=composer.reply - placeholder=replyPlaceholder + placeholderTranslated=replyPlaceholder previewUpdated=(action "previewUpdated") markdownOptions=markdownOptions extraButtons=(action "extraButtons") diff --git a/assets/stylesheets/wizard/custom/field.scss b/assets/stylesheets/wizard/custom/field.scss index e5a7f5e2..f2bb3aa0 100644 --- a/assets/stylesheets/wizard/custom/field.scss +++ b/assets/stylesheets/wizard/custom/field.scss @@ -162,4 +162,15 @@ .text-field input { margin-bottom: 0; } + + .text-field, + .textarea-field, + .composer-field { + input[type="text"], + textarea { + &:focus::placeholder { + color: transparent; + } + } + } } diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 43b86698..a21f79bc 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -173,6 +173,7 @@ en: max_length_placeholder: "Maximum length in characters" char_counter: "Character Counter" char_counter_placeholder: "Display Character Counter" + field_placeholder: "Field Placeholder" file_types: "File Types" limit: "Limit" property: "Property" diff --git a/controllers/custom_wizard/admin/wizard.rb b/controllers/custom_wizard/admin/wizard.rb index 0af55d95..9b128d4d 100644 --- a/controllers/custom_wizard/admin/wizard.rb +++ b/controllers/custom_wizard/admin/wizard.rb @@ -109,6 +109,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController :format, :limit, :property, + :placeholder, prefill: mapped_params, content: mapped_params, condition: mapped_params, diff --git a/lib/custom_wizard/builder.rb b/lib/custom_wizard/builder.rb index 3dd881e7..03f036c8 100644 --- a/lib/custom_wizard/builder.rb +++ b/lib/custom_wizard/builder.rb @@ -186,6 +186,16 @@ class CustomWizard::Builder ) end + if field_template['placeholder'].present? + params[:placeholder] = mapper.interpolate( + field_template['placeholder'], + user: true, + value: true, + wizard: true, + template: true + ) + end + field = step.add_field(params) end diff --git a/lib/custom_wizard/field.rb b/lib/custom_wizard/field.rb index a8160b4c..36a800c1 100644 --- a/lib/custom_wizard/field.rb +++ b/lib/custom_wizard/field.rb @@ -20,7 +20,8 @@ class CustomWizard::Field :format, :limit, :property, - :content + :content, + :placeholder attr_accessor :index, :step @@ -44,6 +45,7 @@ class CustomWizard::Field @limit = attrs[:limit] @property = attrs[:property] @content = attrs[:content] + @placeholder = attrs[:placeholder] end def label @@ -63,18 +65,21 @@ class CustomWizard::Field max_length: nil, prefill: nil, char_counter: nil, - validations: nil + validations: nil, + placeholder: nil }, textarea: { min_length: nil, max_length: nil, prefill: nil, - char_counter: nil + char_counter: nil, + placeholder: nil }, composer: { min_length: nil, max_length: nil, - char_counter: nil + char_counter: nil, + placeholder: nil }, text_only: {}, date: { diff --git a/lib/custom_wizard/validators/update.rb b/lib/custom_wizard/validators/update.rb index 93d4955f..c722a763 100644 --- a/lib/custom_wizard/validators/update.rb +++ b/lib/custom_wizard/validators/update.rb @@ -32,11 +32,11 @@ class ::CustomWizard::UpdateValidator @updater.errors.add(field_id, I18n.t('wizard.field.required', label: label)) end - if min_length && value.is_a?(String) && value.strip.length < min_length.to_i + if min_length.present? && value.is_a?(String) && value.strip.length < min_length.to_i @updater.errors.add(field_id, I18n.t('wizard.field.too_short', label: label, min: min_length.to_i)) end - if max_length && value.is_a?(String) && value.strip.length > max_length.to_i + if max_length.present? && value.is_a?(String) && value.strip.length > max_length.to_i @updater.errors.add(field_id, I18n.t('wizard.field.too_long', label: label, max: max_length.to_i)) end diff --git a/serializers/custom_wizard/wizard_field_serializer.rb b/serializers/custom_wizard/wizard_field_serializer.rb index 42d5eba0..fe22fdeb 100644 --- a/serializers/custom_wizard/wizard_field_serializer.rb +++ b/serializers/custom_wizard/wizard_field_serializer.rb @@ -71,6 +71,7 @@ class CustomWizard::FieldSerializer < ::ApplicationSerializer end def placeholder + return object.placeholder if object.placeholder.present? I18n.t("#{object.key || i18n_key}.placeholder", default: '') end diff --git a/spec/components/custom_wizard/wizard_spec.rb b/spec/components/custom_wizard/wizard_spec.rb index 1c38ab1f..67905f5a 100644 --- a/spec/components/custom_wizard/wizard_spec.rb +++ b/spec/components/custom_wizard/wizard_spec.rb @@ -199,6 +199,7 @@ describe CustomWizard::Wizard do end it "lists the site categories" do + Site.clear_cache expect(@wizard.categories.length).to eq(1) end