I store time as an integer of minutes in the database/model. However, I want to display it to the user in decimal hours (and let them edit the value using a number of buttons).
At the moment I have this:
<p class="input-group">
<input type="text" readonly="readonly" value="{{vm.time.minutes|hoursMinutes}}" class="form-control" />
<span class="input-group-btn">
<ix-time-picker minutes="vm.time.minutes"></ix-time-picker>
</span>
</p>
Of the 2 elements in the p
tag:
- The
input type="text"
works fine as the display mechanism. ThehoursMinutes
filter returns a formatted value, e.g. for 90 mins it will return '1 hour 30 mins'. - The
ix-time-picker
directive pops up a modal window with buttons such as15 mins
,30 mins
,45 mins
,1 hour
,1:15 hours
, etc.
This works fine - except for validation. I'm using ng-messages
and I can't work out how to display the validation for the required
state:
<li class="help-block has-error"
ng-if="mainForm.$submitted"
ng-messages="mainForm.minutes.$error">
<span ng-message="required">
Minutes is required.
</span>
</li>
I don't have a control on the form called minutes
(at least with an ng-model
) so it won't display the message. I could add a hidden input
with ng-model="vm.times.minutes"
but as I need to use this repeatedly through the application, I'd prefer not to do that. Or at least I'd like to build some kind of common directive that merges the ability to have an ng-model
on a control with the ability to display a value
that is different to the model value, if that's possible.
Any suggestions?