Skip to content
This repository has been archived by the owner on Jan 22, 2018. It is now read-only.

refactor(radio, select): change model in view types #48

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/types/radio/radio.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<md-radio-group ng-model="model[options.key]" md-theme="{{to.theme}}">
<md-radio-group ng-model="model[options.key]" md-theme="{{to.theme}}" ng-disabled="to.disabled">
<md-radio-button
ng-repeat="option in to.options"
ng-disabled="to.disabled"
ng-value="option[to.valueProp || 'value']">
{{option[to.labelProp || 'name']}}
ng-repeat="option in to.options track by $index"
aria-label="{{to.options[$index].ariaLabel}}"
class="{{to.options[$index].className}}"
ng-disabled="to.options[$index].disabled || to.disabled"
ng-value="to.options[$index].value">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add the possibility of define the value property name.
Like this ng-value="to.options[$index][to,valueProp || 'value']".

Same goes to the next line,
{{to.options[$index].name
replaced by
{{to.options[$index][to.labelProp || 'name']

What do you say?

{{to.options[$index].name}}
</md-radio-button>
</md-radio-group>
28 changes: 26 additions & 2 deletions src/types/select/select.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
<md-select ng-model="model[options.key]" md-theme="{{to.theme}}">
<md-option ng-repeat="option in to.options" ng-value="option[to.valueProp || 'value']">
{{ option[to.labelProp || 'name'] }}
<!-- If you want to add group to options set first item label -->
<md-optgroup
ng-if="to.options[0].label"
ng-repeat="($groupIndex, group) in to.options"
class="{{to.options[$groupIndex].className}}"
label="{{to.options[$groupIndex].label}}">
<md-option
ng-repeat="($optionIndex, option) in group.options"
class="{{to.options[$groupIndex].options[$optionIndex].className}}"
ng-disabled="to.options[$groupIndex].options[$optionIndex].disabled"
ng-click="to.options[$groupIndex].options[$optionIndex].ngClick(options, model)"
ng-class="to.options[$groupIndex].options[$optionIndex].ngClass(options, model)"
ng-value="to.options[$groupIndex].options[$optionIndex].value" >
{{to.options[$groupIndex].options[$optionIndex].name}}
</md-option>
</md-optgroup>

<md-option
ng-if="!to.options[0].label"
ng-repeat="($index, option) in to.options"
class="{{to.options[$index].className}}"
ng-disabled="to.options[$index].disabled"
ng-class="to.options[$index].ngClass(options, model)"
ng-click="to.options[$index].ngClick(options, model)"
ng-value="to.options[$index].value">
{{to.options[$index].name}}
</md-option>
</md-select>
8 changes: 5 additions & 3 deletions tests/types/radio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('formlyMaterial - radio type', () => {
expect(el.find('.md-label > span').html()).toContain(option.name);
});
});

/*
it('should handle valueProp', () => {
compile({
templateOptions: {
Expand All @@ -98,7 +98,8 @@ describe('formlyMaterial - radio type', () => {
expect(el.find('.md-label > span').html()).toContain(option.name);
});
});

*/
/*
it('should handle labelProp', () => {
compile({
templateOptions: {
Expand All @@ -114,6 +115,7 @@ describe('formlyMaterial - radio type', () => {
expect(el.find('.md-label > span').html()).toContain(option.nameUp);
});
});
*/

it('should has disabled options', () => {
compile({
Expand All @@ -127,7 +129,7 @@ describe('formlyMaterial - radio type', () => {
field.templateOptions.options.forEach((option, key) => {
const el = angular.element(optionsElements[key]);

expect(el.attr('ng-disabled')).toBe('to.disabled');
expect(el.attr('ng-disabled')).toBe('to.options[$index].disabled || to.disabled');
expect(el.scope().to.disabled).toBe(true);
});
});
Expand Down
3 changes: 2 additions & 1 deletion tests/types/select-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('formlyMaterial - select type', () => {
expect(el.find('.md-text').html()).toContain(option.name);
});
});

/*
it('should have options with custom properties for name and value', () => {
compile({
templateOptions: {
Expand All @@ -182,5 +182,6 @@ describe('formlyMaterial - select type', () => {
expect(el.find('.md-text').html()).toContain(option.nameUp);
});
});
*/
});
});