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

Cannot disable individual options in select #57

Open
elyas-bhy opened this issue Dec 23, 2016 · 7 comments
Open

Cannot disable individual options in select #57

elyas-bhy opened this issue Dec 23, 2016 · 7 comments

Comments

@elyas-bhy
Copy link

We currently cannot disable individual options in the select component:

{
  type: "select",
  key: "name",
  templateOptions: {
    label: "Name",
    theme: "custom",
    multiple: true,
    labelProp: "firstName",
    valueProp: "id",
    options: [
        {firstName: "Sarah", id: 1, disabled: true},  // I need to display this option in a disabled state
        {firstName: "Jessica", id: 2},
        {firstName: "Parker", id: 3}
    ],
    onOpen: () => {
      console.log('select is opened');
    },
    onClose: () => {
      console.log('select is closed');
    }
  }
}
@gmanriqueUy
Copy link

@kamilkisiela if I make a PR for this, would you merge it?

@kamilkisiela
Copy link
Collaborator

@U-like YES!

@kamilkisiela
Copy link
Collaborator

@U-like @mention me there

Maybe you want to take in charge of this repository?

@gmanriqueUy
Copy link

@kamilkisiela I really would like that, but I've never been in charge of a repository. Maybe this is an opportunity to learn how to do it.

@pdonorio
Copy link

@U-like please do! This is very important for people using Formly and Angular Material, they are both great tools!

@vincaslt
Copy link

vincaslt commented Mar 6, 2017

Angular documentation specifies, that to disable a single option you need to set notAnOption flag to true. I'd say this should be implemented here, dang I was sure I've seen it working previously with this lib..

Imho, it's as simple as adding: <md-option ng-disabled="option.notAnOption" ...>.

@vincaslt
Copy link

For my use case, I did this sort of workaround:

  formlyConfig.setType({
      name: 'my-select',
      extends: 'select',
      template: `
        <md-select ng-model="model[options.key]" md-theme="{{to.theme}}">
          <md-option ng-disabled="option.notAnOption" ng-repeat="option in to.options" ng-value="option[to.valueProp || 'value']">
            {{ option[to.labelProp || 'name'] }}
          </md-option>
        </md-select>
      `
    });

And you can mark option as disabled as per angular docs: { name: '...', value: '...', notAnOption: true }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants