Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

$dirty is true when no changes were made and 'options' came via json array (or similar) #151

Closed
genuinefafa opened this issue Feb 6, 2014 · 38 comments

Comments

@genuinefafa
Copy link

Following #6 that is closed and mostly angular-ui/angular-ui-OLDREPO#268 (from the old repo).

I'm using the latest tagged version 0.0.5 and found that $dirty is always true when the form is loaded and the options came via a json array.

AFAIK It should be false if no changes were made.

Any clue on how to fix it? I made an example plunkr.

@johnsouth
Copy link

I just ran into the exact same issue myself. The solution I found required a slight tweak to the code. No PR because it's a quick hack with no testing and I suck at git. Sorry. :-/

So, find your existing $watch method and move the "elm.trigger('change');" line to within an "else" statement. If this breaks other stuff, feel free to tell me I'm horribly wrong, I only just figured this out a few minutes ago.

      // Watch the options dataset for changes
      if (watch) {
        scope.$watch(watch, function (newVal, oldVal, scope) {
          if (angular.equals(newVal, oldVal)) {
            return;
          }
          // Delayed so that the options have time to be rendered
          $timeout(function () {
            elm.select2('val', controller.$viewValue);

            if(newVal && !oldVal && controller.$setPristine) {
                controller.$setPristine(true);
            } else {
                // Refresh angular
                elm.trigger('change');
            }
          });
        });
      }

@micheee
Copy link

micheee commented May 6, 2014

👍 to anyone could/knew how to fix this.

@vrodriguezTecsisa
Copy link

+1

@HoffZ
Copy link

HoffZ commented May 7, 2014

+5000 (on the behalf of everyone using our app)

@HoffZ
Copy link

HoffZ commented May 8, 2014

Your hack is not working for me, @johnsouth. Could you apply your fix to the Plunker from @genuinefafa?

@ChristianGruen
Copy link

Any chance to fix this soon?

@NMichas
Copy link

NMichas commented May 13, 2014

Unfortunately, none of these solutions seem to work - including #173 and #208 .

@MilosMosovsky
Copy link
Contributor

@ChristianGruen @NMichas
All of my problems was causing that i was initializing select2 on input type="text" try to change your code to input type="hidden" as it is triggering different events.

Tell me if it helps :)

@ChristianGruen
Copy link

Thanks @mavericker. Unfortunately, it doesn’t seem to help. In fact, <input type="text"/> doesn’t work at all; we need to use either <div/> or <input type="hidden"/>:

<input type="hidden" ui-select2="settings.select2Options" ng-model="..."/>
$settings.select2Options = {
  multiple: true,
  ajax: { ... }
};

@MilosMosovsky
Copy link
Contributor

Are you able to post code where you have problems? I have already solved all problems inside my project. So maybe i will help you.

@ChristianGruen
Copy link

Unfortunately not, but we’ll try to create a reproducible example. Thanks in advance!

@MilosMosovsky
Copy link
Contributor

Are you able to change

https://github.com/angular-ui/ui-select2/blob/master/src/select2.js#L127

from

  elm.trigger('change');

to

   controller.$render();

and

https://github.com/angular-ui/ui-select2/blob/master/src/select2.js#L209

from

   var isPristine = controller.$pristine;
            controller.$setViewValue(
              convertToAngularModel(elm.select2('data'))
            );
            if (isPristine) {
              controller.$setPristine();
            }

to

 var isPristine = controller.$pristine;
 controller.$pristine = false;
            controller.$setViewValue(
              convertToAngularModel(elm.select2('data'))
            );
            if (isPristine) {
              controller.$setPristine();
            }

@ChristianGruen
Copy link

This could be the solution! I’ll do some more testing tomorrow and will let you know if everything works as expected…

@MilosMosovsky
Copy link
Contributor

I have it integrated inside approx 700-1000 select boxes and everything seems to be fine. When you will test it inside your app i will post new PR . Thanks for reply

@HoffZ
Copy link

HoffZ commented May 15, 2014

You're solution works for me, @mavericker 👍

@MilosMosovsky
Copy link
Contributor

Thank you very much for response i will post PR today :)

@ChristianGruen
Copy link

Confirmed; works fine ;)

@ChristianGruen
Copy link

Sorry for pushing this… Did sth. go wrong in the pull request?

@MilosMosovsky
Copy link
Contributor

Nope i just forget :) Will make it tonight.

2014-05-19 20:11 GMT+02:00 Christian Gruen [email protected]:

Sorry for pushing this… Did sth. go wrong in the pull request?


Reply to this email directly or view it on GitHubhttps://github.com//issues/151#issuecomment-43537380
.

@MilosMosovsky
Copy link
Contributor

Finally found time , here you are
@ChristianGruen
@HoffZ

@genuinefafa
Copy link
Author

I'm not sure if I shall test it again, or if you are going to release a new version now that this issue was solved.

ps: I was silent, but not deft ;)

@MilosMosovsky
Copy link
Contributor

That fix is working , but somehow travis is failing with some bower error. I am not able to automatic merge it to master ....

@MilosMosovsky
Copy link
Contributor

@genuinefafa Take PR #215 it is tested by Christian and HoffZ and also by me.

@arolle
Copy link

arolle commented May 23, 2014

Any news? Has this already been merged?

@MilosMosovsky
Copy link
Contributor

I cant merge it , but not because error but travis build is erroring due bower install. I am not able to merge it , even if all tests passed

https://travis-ci.org/angular-ui/ui-select2/builds/25719951

@ChristianGruen
Copy link

Thanks for the feedback. Any chance to help you?

@MilosMosovsky
Copy link
Contributor

I cant find any contact to project maintaner to contact him about issues with build, if you can help me with that i would be happy 👯

@ChristianGruen
Copy link

@mavericker: I wrote to their mailing list. What do you think about the warning?.. https://groups.google.com/forum/#!topic/travis-ci/zGqeu3Uso9E

@MilosMosovsky
Copy link
Contributor

Hello i dont think it is commit related, because when you make clean FORK of latest ui-select2 master, and edit for example 1 line inside README.md. you will gete this error. So i think its related to ui-select2 build config..... or maybe travis is bugged.

Error is :
fstream_stack Object.oncomplete (fs.js:297:15)

npm ERR! Error: No compatible version found: minimatch@'^0.3.0'

npm ERR! Valid install targets:

npm ERR! ["0.0.1","0.0.2","0.0.4","0.0.5","0.1.1","0.1.2","0.1.3","0.1.4","0.1.5","0.2.0","0.2.2","0.2.3","0.2.4","0.2.5","0.2.6","0.2.7","0.2.8","0.2.9","0.2.10","0.2.11","0.2.12","0.2.13","0.2.14","0.3.0"]

But dependency is not required by my code, but from select2 itself. If you understand what i mean ....

@ChristianGruen
Copy link

I think I understand. Do you know who’s responsible for the ui-select2 master and the build configuration?

@MilosMosovsky
Copy link
Contributor

I think https://github.com/ProLoser this guy , maybe contact him trough
contact form on his website??

2014-05-27 10:49 GMT+00:00 Christian Gruen [email protected]:

I think I understand. Do you know who’s responsible for the ui-select2
master and the build configuration?


Reply to this email directly or view it on GitHubhttps://github.com//issues/151#issuecomment-44259892
.

@ChristianGruen
Copy link

...waiting for some feedback.

On Tue, May 27, 2014 at 12:53 PM, Mavericker [email protected]
wrote:

I think https://github.com/ProLoser this guy , maybe contact him trough
contact form on his website??

2014-05-27 10:49 GMT+00:00 Christian Gruen [email protected]:

I think I understand. Do you know who's responsible for the ui-select2
master and the build configuration?

Reply to this email directly or view it on GitHub<
https://github.com/angular-ui/ui-select2/issues/151#issuecomment-44259892>

.

Reply to this email directly or view it on GitHub
#151 (comment)
.

@shanesmith
Copy link

I've confirmed that PR #215 fixes the issue for me. Any word from the maintainers?

@MilosMosovsky
Copy link
Contributor

i think they left this repo and started maintaining new version of select2 https://github.com/angular-ui/ui-select its native version without jquery and original select2, i can confirm that it works very well .... try to replace your select2 with the new one.

@genuinefafa
Copy link
Author

@MilosMosovsky do you think is the select2 native version is as stable as this one? I did a dry-run to a simple project and found it pretty slim. :(

gpeshans pushed a commit to netceteragroup/ui-select2 that referenced this issue Jul 30, 2014
- updated to latest select2 and jquery
- add minified version
@gpeshans
Copy link

I made a new release that includes the fix proposed here and it is available on bower by 'angular-nca-select2'. There is also a minified version in the release. We use this as a temporary solution in our project and it will be deleted when a new version of angular-ui-select2 is published. Thanks @MilosMosovsky :)

ProLoser added a commit that referenced this issue Aug 1, 2014
Fix incorrect dirty flag when initializing from JSON #151
@genuinefafa
Copy link
Author

@PesanskiGoran does your version differs from the uploaded here, how? I mean, the PR was accepted and is now working, is it not?

My project has some workaround for this issue. I need to do major changes now to test this. I would prefer having all the required information first :bowtie:

@philippd
Copy link

philippd commented Aug 4, 2014

@genuinefafa The pull request is now in the master, but there is no release available yet. The version from @PesanskiGoran is based on the latest master (including the fix described above) and contains also a minified version of angular-ui-select2. The repo is only a temporary workaround for us until the fix is available in a version via bower.

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