I am currently passing some values to hidden fields via buttons and some javascript.
I want to somehow transition the values into my controller to protect them from being manually over written.
Is there a way to have a boolean checkbox pass a string value?
My Current Setup
<div class="btn-group event_color" data-toggle="buttons-radio">
<button type="button" class="btn" value="#5BB65B">Active</button>
<button type="button" class="btn" value="#FAA732">Pending</button>
<button type="button" class="btn" value="#DA4F49">On Hold</button>
<%=f.hidden_field :color %>
<%=f.hidden_field :event_status %>
</div>
JS
$(".event_color .btn").click(function() {
// whenever a button is clicked, set the hidden helper
$('#event_color').val($(this).val());
});
$(".event_color .btn").click(function() {
// whenever a button is clicked, set the hidden helper
$("#event_event_status").val($(this).text());
});
Right now a user can open up a web browsing editor tool and overwrite the values.
Basically I want to setup booleans as :approved, :pending and :on_hold and then pass the strings values listed above to update the :color. I attempted this before, but the DB would not update it on the first save. I had to go back and re-save again for it to pickup which checkbox was clicked
Boolean Setup that I tested but would not save the first time
<div class="radio-style">
<%= f.check_box :active %><%= f.label :active %>
<%= f.check_box :pending %><%= f.label :pending %>
<%= f.check_box :on_hold %><%= f.label :on_hold %>
</div>
Event Controller
def set_event_color
if @event.active?
@event.color = "#000000"
else if @event.pending?
@event.color = "#000000"
else if @event.on_hold
@event.color = "#000000"
end
end
end