Skip to content

Commit

Permalink
Added required class to text input label
Browse files Browse the repository at this point in the history
  • Loading branch information
palsimen-datek committed Sep 12, 2023
1 parent 8158a88 commit c57d58e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ build/
gradle.properties

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
.idea/
*.iws
*.iml
*.ipr
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group 'no.datek'
version '0.6.2'
version '0.6.3'
final String JRUBY_VERSION = '9.4.3.0';

repositories {
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/ruby/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ def text_input(object, field_name, **opts)
id_name = opts.delete(:id) || field_name.to_s.gsub('.', '_')
disabled = opts.delete(:disabled)
readonly = opts.delete(:readonly)
required = opts.delete(:required)
type = opts.delete(:type) || 'text'
value = opts.delete(:value)
placeholder = opts.delete(:placeholder)

html = ""
field_value = value || object_field_value(object, field_name)
html << %{<input type="#{type}" name="#{field_name}" id="#{id_name}" value="#{field_value}"}
html << %{ #{:disabled if disabled} #{:readonly if readonly} #{"placeholder='#{placeholder}'" if placeholder}}
html << %{ #{:disabled if disabled} #{:readonly if readonly} #{:required if required} #{"placeholder='#{placeholder}'" if placeholder}}
opts.each do |key, value|
html << %{ #{key}="#{value}"}
end
Expand Down Expand Up @@ -159,12 +160,13 @@ def bootstrap_text_input(object, field_name, **opts)
label_style = opts.delete(:label_style)
append = opts.delete(:append)
wrapper_class = opts.key?(:wrapper_class) ? opts.delete(:wrapper_class) : 'mb-3'
required = opts[:required]

if hide_label
html = ''
else
label = label == '' ? '&nbsp;' : CGI.escapeHTML(label)
html = %{<label for="#{field_name}" class="#{label_class}"}
html = %{<label for="#{field_name}" class="#{label_class} #{:required if required}"}
html << %{ style="#{label_style}"} if label_style
html << %{>#{label}</label> }
end
Expand Down

0 comments on commit c57d58e

Please sign in to comment.