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

Fix the "mandatory" asterisk not updating properly #4321

Merged
merged 2 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion jsapp/xlform/src/view.mandatorySetting.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = do ->
'blur .js-mandatory-setting-custom-text': 'onCustomTextBlur'
}

initialize: ({@model}) ->
initialize: ({@model, @onChange}) ->
if @model
@model.on('change', @render, @)
return
Expand Down Expand Up @@ -63,6 +63,9 @@ module.exports = do ->

setNewValue: (val) ->
@model.set('value', val)

if typeof @onChange is 'function'
@onChange(val)
return

MandatorySettingView: MandatorySettingView
17 changes: 15 additions & 2 deletions jsapp/xlform/src/view.row.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ module.exports = do ->
@model.finalize()
val.set('value', '')
view.render().insertInDOM(@)
if @model.getValue('required')
@$card.addClass('card--required')

# Initialize the mandatory asterisk
@_onMandatorySettingChange(@model.getValue('required'))

return @

Expand Down Expand Up @@ -417,6 +418,17 @@ module.exports = do ->
@applyLocking()
return @

# Updates the "mandatory" asterisk on the row card when settings change.
# Also called on initial card rendering.
# NOTE: the MandatorySettingView responds with a string (e.g. 'false') but
# the initial rendering method is passing a boolean.
_onMandatorySettingChange: (newVal) ->
if newVal and newVal isnt 'false' and newVal isnt ''
@$card.addClass('card--required')
else
@$card.removeClass('card--required')
return

_expandedRender: ->
@$header.after($viewTemplates.row.rowSettingsView())
@cardSettingsWrap = @$('.card__settings').eq(0)
Expand All @@ -428,6 +440,7 @@ module.exports = do ->
if key is 'required'
@mandatorySetting = new $viewMandatorySetting.MandatorySettingView({
model: @model.get('required')
onChange: @_onMandatorySettingChange.bind(@)
}).render().insertInDOM(@)
else if key is '_isRepeat' and @model.getValue('type') is 'kobomatrix'
# don't display repeat checkbox for matrix groups
Expand Down