Skip to content

Commit

Permalink
[FEATURE] Translate input element
Browse files Browse the repository at this point in the history
refs OSC-17
  • Loading branch information
Bunhok committed Sep 21, 2022
1 parent 5e76c27 commit ef8f278
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
4 changes: 3 additions & 1 deletion app/assets/javascripts/custom_form_builder.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ class CIF.CustomFormBuilder
self.preventClickEnterOrTab(fld)
),50

eventTextAreaOption: ->
eventTextAreaOption: (fields = []) ->
self = @
onadd: (fld) ->
$('.rows-wrap, .subtype-wrap, .className-wrap, .value-wrap, .access-wrap, .maxlength-wrap, .description-wrap, .name-wrap').hide()
self.handleCheckingForm()
self.preventClickEnterOrTab(fld)
self.handleAddTranslateLabelField(fld, fields)
onclone: (fld) ->
setTimeout ( ->
self.handleCheckingForm()
Expand Down Expand Up @@ -270,6 +271,7 @@ class CIF.CustomFormBuilder
localLabel = "Local Label"
if fields[index - 1]
localLabel = if fields[index - 1][localLabelName] then fields[index - 1][localLabelName] else localLabel
frmHolder = fldElement.find('.frm-holder')
localLabelBlock = "<div class='form-group local-label-wrap' style='display: block'><label for='#{localLabelName}'>Local Label</label><div class='input-wrap'><div name='#{localLabelName}' placeholder='Local Label' class='fld-label-#{fldId} form-control' id='local-label-#{fldId}' contenteditable='true'>#{localLabel}</div></div></div>"
localLabelBlockElement = $.parseHTML(localLabelBlock)
frmHolder.find('.label-wrap').after(localLabelBlockElement)
12 changes: 12 additions & 0 deletions app/assets/javascripts/multiple_form/form.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ CIF.Client_trackingsNew = CIF.Client_trackingsCreate = CIF.Client_custom_fieldsN
_preventCreateDatePickerClientEnrollment()
_setAnotherLanguageFieldValue()
_hideAnotherLanguageField()
_copyInputTextToLocalLanguage()
_copyTextAreaTextToLocalLanguage()

_initICheckBox = ->
$('.i-checks').iCheck
Expand Down Expand Up @@ -52,6 +54,16 @@ CIF.Client_trackingsNew = CIF.Client_trackingsCreate = CIF.Client_custom_fieldsN
_hideAnotherLanguageField = ->
$('.client-enrollment').find('.d-none').parent().addClass('hide')

_copyInputTextToLocalLanguage = ->
$('input[type="text"]').on 'keyup', (e) ->
el = $(@)
el.parent().next().find('#' + el.data('local-input')).val(el.val())

_copyTextAreaTextToLocalLanguage = ->
$('textarea').on 'keyup', (e) ->
el = $(@)
el.parent().next().find('#' + el.data('local-textarea')).val(el.val())

_preventRequireFields = ->
preventFileUploader()
preventRequireFieldInput()
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/program_streams/form.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ CIF.Program_streamsNew = CIF.Program_streamsEdit = CIF.Program_streamsCreate = C
number: builderOption.eventNumberOption()
'radio-group': builderOption.eventRadioOption()
select: builderOption.eventSelectOption(fields)
text: builderOption.eventTextFieldOption()
textarea: builderOption.eventTextAreaOption()
text: builderOption.eventTextFieldOption(fields)
textarea: builderOption.eventTextAreaOption(fields)
separateLine: builderOption.eventSeparateLineOption()
paragraph: builderOption.eventParagraphOption()
}
Expand Down
6 changes: 4 additions & 2 deletions app/views/shared/fields/_text.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
- label = field_label(field_props)
%div{ class: "form-group #{field_with(field_props['label'],errors)}" }
%label.control-label{ class: required?(field_props['required'] || false) }
%abbr{ title: 'required' }= '*' if field_props['required'] || false
= field_props['label'].html_safe
= f.input field_props['label'], required: (field_props['required'] || false), input_html: { class: field_props['className'], placeholder: format_placeholder(field_props['placeholder']), title: field_props['description'], name: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]", type: field_props['subtype'] , id: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]".parameterize}, label: false
= label.html_safe
= f.input field_props['label'], required: (field_props['required'] || false), input_html: { class: field_props['className'], placeholder: format_placeholder(field_props['placeholder']), title: field_props['description'], name: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]", type: field_props['subtype'] , id: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]".parameterize, 'data-local-input': "#{f.object_name}[#{remove_local_field_prop_unicode(field_props)}]".parameterize }, label: false
= f.input field_props['local_label'], :as => :hidden, input_html: { name: "#{f.object_name}[Local_label #{remove_local_field_prop_unicode(field_props)}]", id: "#{f.object_name}[#{remove_local_field_prop_unicode(field_props)}]".parameterize }
%span.help-block
= field_message(field_props['label'], errors)
6 changes: 4 additions & 2 deletions app/views/shared/fields/_textarea.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
- label = field_label(field_props)
%div{ class: "form-group #{field_with(field_props['label'],errors)}" }
%label.control-label{ class: required?(field_props['required'] || false) }
%abbr{ title: 'required' }= '*' if field_props['required'] || false
= field_props['label'].html_safe
= f.input field_props['label'], as: :text, required: (field_props['required'] || false), input_html: { class: field_props['className'], placeholder: format_placeholder(field_props['placeholder']), name: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]" }, label: false
= label.html_safe
= f.input field_props['label'], as: :text, required: (field_props['required'] || false), input_html: { class: field_props['className'], placeholder: format_placeholder(field_props['placeholder']), name: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}]", 'data-local-textarea': "#{f.object_name}[#{remove_local_field_prop_unicode(field_props)}]".parameterize }, label: false
= f.input field_props['local_label'], :as => :hidden, input_html: { name: "#{f.object_name}[Local_label #{remove_local_field_prop_unicode(field_props)}]", id: "#{f.object_name}[#{remove_local_field_prop_unicode(field_props)}]".parameterize }
%span.help-block
= field_message(field_props['label'], errors)

0 comments on commit ef8f278

Please sign in to comment.