Skip to content

Commit

Permalink
Set radio buttons w/ jQuery instead of in template
Browse files Browse the repository at this point in the history
Bootstrap seems to behave weird when trying to set the `checked` attribute on a radio button in advance, so just use jQuery to do it instead.
  • Loading branch information
mvandenburgh committed Jul 21, 2022
1 parent 3d4bc4b commit dd0cf60
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions histomicsui/web_client/panels/DrawWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,9 @@ var DrawWidget = Panel.extend({
}

$(e.target).parent().find('.h-dropdown-content').collapse('toggle');

// Select the corresponding radio button for the current size_mode
$(`input[mode="${this._editOptions.size_mode || 'unconstrained'}"]`, $(e.target.parentNode)).trigger('click');
},

/**
Expand Down
12 changes: 6 additions & 6 deletions histomicsui/web_client/templates/panels/drawWidget.pug
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ block content
.h-fixed-shape-controls.h-dropdown-content.collapse
.form-group.h-fixed-shape-form-group.input-sm
label.radio
input.h-fixed-shape.h-brush-square(type="radio", name="h-fixed-shape", checked=opts.size_mode !== 'fixed_aspect_ratio' && opts.size_mode !== 'fixed_size' ? 'checked' : undefined, mode="unconstrained")
input.h-fixed-shape(type="radio", name="h-fixed-shape", mode="unconstrained")
| Unconstrained
label.radio
input.h-fixed-shape.h-brush-square(type="radio", name="h-fixed-shape", checked=opts.size_mode === 'fixed_aspect_ratio' ? 'checked' : undefined, mode="fixed_aspect_ratio")
input.h-fixed-shape(type="radio", name="h-fixed-shape", mode="fixed_aspect_ratio")
| Fixed Aspect Ratio
label.radio
input.h-fixed-shape.h-brush-circle(type="radio", name="h-fixed-shape", checked=opts.size_mode === 'fixed_size' ? 'checked' : undefined, mode="fixed_size")
input.h-fixed-shape(type="radio", name="h-fixed-shape", mode="fixed_size")
| Fixed Size
.form-group.h-fixed-shape-form-group.h-fixed-values.input-sm
label
Expand All @@ -50,13 +50,13 @@ block content
.h-fixed-shape-controls.h-dropdown-content.collapse
.form-group.h-fixed-shape-form-group.input-sm
label.radio
input.h-fixed-shape.h-brush-square(type="radio", name="h-fixed-shape", checked=opts.size_mode !== 'fixed_aspect_ratio' && opts.size_mode !== 'fixed_size' ? 'checked' : undefined, mode="unconstrained")
input.h-fixed-shape(type="radio", name="h-fixed-shape", mode="unconstrained")
| Unconstrained
label.radio
input.h-fixed-shape.h-brush-square(type="radio", name="h-fixed-shape", checked=opts.size_mode === 'fixed_aspect_ratio' ? 'checked' : undefined, mode="fixed_aspect_ratio")
input.h-fixed-shape(type="radio", name="h-fixed-shape", mode="fixed_aspect_ratio")
| Fixed Aspect Ratio
label.radio
input.h-fixed-shape.h-brush-circle(type="radio", name="h-fixed-shape", checked=opts.size_mode === 'fixed_size' ? 'checked' : undefined, mode="fixed_size")
input.h-fixed-shape(type="radio", name="h-fixed-shape", mode="fixed_size")
| Fixed Size
.form-group.h-fixed-shape-form-group.h-fixed-values.input-sm
label
Expand Down

0 comments on commit dd0cf60

Please sign in to comment.