fix label id missing for front-end form
This commit is contained in:
parent
e8f8079cf8
commit
9d01096e13
|
@ -390,7 +390,8 @@ class AsksController < ApplicationController
|
|||
if v
|
||||
field_name = info['trans']
|
||||
if field_name.present?
|
||||
all_fields << {'field'=>field,'label'=>ask_label(field_name, v['required']),'content'=>show_on_front(k,v)}
|
||||
id = "#{get_input_name_for_ask}[custom_values][#{k}]"
|
||||
all_fields << {'field'=>field,'label'=>ask_label(id, field_name, v['required']),'content'=>show_on_front(k,v)}
|
||||
end
|
||||
end
|
||||
elsif field.start_with?("custom@") && is_cat_record
|
||||
|
@ -400,7 +401,8 @@ class AsksController < ApplicationController
|
|||
if v
|
||||
field_name = info['trans']
|
||||
if field_name.present?
|
||||
all_fields << {'field'=>field,'label'=>ask_label(v['field'][I18n.locale],v['required']),'content'=>show_on_front(k,v)}
|
||||
id = "#{get_input_name_for_ask}[custom_values][#{k}]"
|
||||
all_fields << {'field'=>field,'label'=>ask_label(id, v['field'][I18n.locale],v['required']),'content'=>show_on_front(k,v)}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -409,9 +411,10 @@ class AsksController < ApplicationController
|
|||
has_ask_category_id = true
|
||||
if show_categories || ask_setting.default_setting[field]
|
||||
if categories.count > 1
|
||||
all_fields << {'field'=>field,'style_html'=>'','label'=>ask_label(@default_ask_setting.field_name("ask_category_id"),'true'),'content'=>select_tag('ask_question[category_id]', options_for_select(categories.collect{|t| [ t.title, t.id ]}))}
|
||||
id = "ask_question[category_id]"
|
||||
all_fields << {'field'=>field,'style_html'=>'','label'=>ask_label(id, @default_ask_setting.field_name("ask_category_id"),'true'),'content'=>select_tag('ask_question[category_id]', options_for_select(categories.collect{|t| [ t.title, t.id ]}))}
|
||||
else
|
||||
all_fields << {'field'=>field,'style_html'=>'','label'=>ask_label(@default_ask_setting.field_name("ask_category_id"),'true'),'content'=>"<span>#{(categories[0].title rescue '')}</span>"+hidden_field_tag('ask_question[category_id]', (categories[0].id.to_s rescue ''))}
|
||||
all_fields << {'field'=>field,'style_html'=>'','label'=>ask_label(nil, @default_ask_setting.field_name("ask_category_id"),'true'),'content'=>"<span>#{(categories[0].title rescue '')}</span>"+hidden_field_tag('ask_question[category_id]', (categories[0].id.to_s rescue ''))}
|
||||
end
|
||||
else
|
||||
all_fields << {'field'=>field,'style_html'=>'display: none;','label'=>'','content'=>hidden_field_tag('ask_question[category_id]', (categories[0].id.to_s rescue ''))}
|
||||
|
@ -419,15 +422,17 @@ class AsksController < ApplicationController
|
|||
else
|
||||
if ask_setting.default_setting[field] || field == "usage_rule"
|
||||
required = ask_setting.is_required(field)
|
||||
f1 = {'style_html'=>'','label'=>ask_label(@default_ask_setting.field_name("#{field}"),required.to_s)}
|
||||
f1 = {'style_html'=>''}
|
||||
field_name = "ask_question[#{field}]"
|
||||
placeholder = @default_ask_setting.prompt_word(field)
|
||||
id = field_name
|
||||
case field
|
||||
when 'title'
|
||||
f1['content'] = text_field_tag(field_name,nil,placeholder: placeholder,required: required)
|
||||
when 'name'
|
||||
f1['content'] = text_field_tag(field_name,nil,data: (required ? {"fv-validation" => "required;", "fv-messages" => "必填欄位;"} : {}),required: required,placeholder: placeholder)
|
||||
when 'sex'
|
||||
id += "_male"
|
||||
f1['content'] = "<label class=\"radio-inline\">
|
||||
#{radio_button_tag(field_name,'male', false, {required: required})}#{I18n.t('users.male')}
|
||||
</label>
|
||||
|
@ -444,18 +449,21 @@ class AsksController < ApplicationController
|
|||
else
|
||||
@appointment_idx += 1
|
||||
end
|
||||
f1['content'] = "<div class=\"default_picker\">#{text_field_tag(field_name,nil,placeholder: placeholder,data: {format: 'yyyy/MM/dd hh:mm'},required: required, id: "ask_question_appointment_#{@appointment_idx}")}</div>"
|
||||
id = "ask_question_appointment_#{@appointment_idx}"
|
||||
f1['content'] = "<div class=\"default_picker\">#{text_field_tag(field_name,nil,placeholder: placeholder,data: {format: 'yyyy/MM/dd hh:mm'},required: required, id: id)}</div>"
|
||||
when 'recaptcha'
|
||||
f1['content'] = "#{gotcha_error(:espeak=>true)}#{gotcha}"
|
||||
id = "ask_rucaptcha"
|
||||
f1['content'] = "#{gotcha_error(:espeak=>true)}#{gotcha(id: id)}"
|
||||
when 'usage_rule'
|
||||
next if ask_setting.usage_rule.blank?
|
||||
f1['content'] = ask_setting.usage_rule
|
||||
when 'agree_show'
|
||||
f1['content'] = check_box_tag('ask_question[agree_show]', "1", false, {required: required})
|
||||
f1['content'] = check_box_tag(field_name, "1", false, {required: required})
|
||||
when 'agree_usage'
|
||||
f1['content'] = check_box_tag('ask_question[agree_usage]', "1", false, {required: required})
|
||||
f1['content'] = check_box_tag(field_name, "1", false, {required: required})
|
||||
end
|
||||
f1['field'] = field
|
||||
f1['label'] = ask_label(id, @default_ask_setting.field_name("#{field}"),required.to_s)
|
||||
all_fields << f1
|
||||
end
|
||||
end
|
||||
|
|
|
@ -205,8 +205,8 @@ module Admin::AsksHelper
|
|||
"
|
||||
end
|
||||
end
|
||||
def ask_label(value,required='false')
|
||||
label_tag(nil,value,{:class=>"control-label#{required=='true' ? ' required' : ''}"})
|
||||
def ask_label(id, value, required='false')
|
||||
label_tag(id,value,{:class=>"control-label#{required=='true' ? ' required' : ''}"})
|
||||
end
|
||||
def format_checkbox(options,value,multple_choose=false)
|
||||
options.select{|index1,option| option['disabled'] != 'true'}.collect do |index1,option|
|
||||
|
@ -338,17 +338,17 @@ module Admin::AsksHelper
|
|||
when 'file'
|
||||
file_value = value[0] rescue nil
|
||||
file_path = value[1] rescue nil
|
||||
file_required = v['required']=='true' ? 'required="required"' : ''
|
||||
file_required = v['required']=='true'
|
||||
readonly ? (file_path ? "<a href=\"#{file_path}\" title=\"file\">#{file_value}</a>" : "") : "<div class=\"file-selector\"><label class=\"ui-button\">
|
||||
<input data-src=\"#{file_path}\" style=\"position: absolute;width:0.1em;opacity: 0;padding: 0;border: 0;opacity: 0;left: 50%;top: 0;\" class=\"upload\" name=\"#{field_name}\" #{file_required} type=\"file\" value=\"#{file_value}\"/>
|
||||
#{file_field_tag(field_name, {:data => {:src => file_path}, style: "position: absolute;width:0.1em;opacity: 0;padding: 0;border: 0;opacity: 0;left: 50%;top: 0;", :class => 'upload', :required => file_required, value: file_value})}
|
||||
<i class=\"fa fa-file\"></i> #{t('ask.upload_file')}
|
||||
</label><div class=\"filename\"></div></div>"
|
||||
when 'image'
|
||||
file_value = value[0] rescue nil
|
||||
file_path = value[1] rescue nil
|
||||
file_required = v['required']=='true' ? 'required="required"' : ''
|
||||
file_required = v['required']=='true'
|
||||
readonly ? (file_value ? "<img src=\"#{file_path}\" alt=\"#{file_value}\">" : "") : "<div class=\"file-selector\"><label class=\"ui-button\">
|
||||
<input data-image-src=\"#{file_path}\" style=\"position: absolute;width:0.1em;padding: 0;border: 0;opacity: 0;left: 50%;top: 0;\" accept=\"image/*\" class=\"upload\" name=\"#{field_name}\" #{file_required} type=\"file\" value=\"#{file_value}\"/>
|
||||
#{file_field_tag(field_name, {:data => {'image-src' => file_path}, style: "position: absolute;width:0.1em;padding: 0;border: 0;opacity: 0;left: 50%;top: 0;", :class => 'upload', :required => file_required, value: file_value, accept: "image/*"})}
|
||||
<i class=\"fa fa-photo\"></i> #{t('ask.upload_image')}
|
||||
</label><div class=\"filename\"></div></div>"
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue