-1

I need to create robot in page to do some work and I need to change value of year and month and submit when a put value manually everything work but when I use javascript like this :

document.getElementsByName('dateeffet-annee')[0].value='2017';
document.getElementsByName('dateeffet-annee')[0].focus();
document.getElementsByName('dateeffet-mois')[0].value='12';
document.getElementsByName('dateeffet-mois')[0].focus();

This is my page code :

<div class="col-xs-12 ap-show" id="tarifs" ng-click="showPanier = false" ng-show="!isLoading" ng-class="{'ap-show':!isLoading}" style="">
    <div class="row">
        <div>
            <!-- ngIf: getNbProposition() == 0 -->
            <div ng-if="getNbProposition() == 0" class="ng-scope">
                <p>Les propositions ne pourront être tarifiées qu'après modification de la date d'effet.</p>
                <div class="col-xs-4 col-xs-offset-4">
                    <div class="input-group ng-valid ng-valid-required ap-invalid ng-dirty" invalid="hasNotify(vm, 'dateeffet')" ng-form="" name="effetFormBis">
                        <div class="input-group date-group ng-isolate-scope ng-valid-date ng-valid-max-date ng-valid-min-date ng-valid ng-valid-required ng-dirty" ng-form="dateeffet" ap-date-containers="" ng-model="vm.dateeffet" ng-change="saveDateEffet()" min-date="" max-date="" ng-required="behaviours['dateeffet-required']" name="dateeffet">
                            <input maxlength="2" name="dateeffet-jour" placeholder="jj" mask="99" class="form-control left ng-pristine ng-valid" ng-model="dateVal.PartJour" ng-focus="focus.jour = true" ng-blur="focus.jour = false" type="tel">
                            <input maxlength="2" name="dateeffet-mois" placeholder="mm" mask="99" class="form-control left ng-pristine ng-valid" ng-model="dateVal.PartMois" ng-focus="focus.mois = true" ng-blur="focus.mois = false" type="tel">
                            <input maxlength="4" name="dateeffet-annee" placeholder="aaaa" mask="9999" class="form-control last ng-pristine ng-valid" ng-model="dateVal.PartAnnee" ng-focus="focus.annee = true" ng-blur="focus.annee = false" type="tel">
                            <input name="compoVal" ng-model="dateVal.PartAnnee" class="ng-pristine ng-valid" type="hidden">
                        </div>
                    </div>
                </div>
            </div>
            <!-- end ngIf: getNbProposition() == 0 -->
            <!-- ngIf: getNbProposition() > 0 -->
        </div>
    </div>
</div>

Can you help to change value and submit changed with javascript from console because this is not my website

Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
Abdelhak
  • 35
  • 9

2 Answers2

0

If you are updating values this way, instead "the angular way" (inside the controller, using angular jqlite), you should execute the code inside a $scope.$apply function, to force angular to update values. Something like this should work outside angular controller:

$scope.$apply(function () {
    document.getElementsByName('dateeffet-annee')[0].value='2017';
    document.getElementsByName('dateeffet-mois')[0].value='12';
});
  • when i execute this code in mozilla i get this message ReferenceError: $scope is not defined – Abdelhak Mar 18 '17 at 10:57
  • @Abdelhak you can't just execute this in a console. This is the code you need in your angular controller to let angular know you're changing values in an 'un-angular' way (manipulating the DOM directly). I'd advice you to follow a (few) good angular tutorial(s) before trying to actually use the framework. The learning curve of angular can be tough. – Nikolaj Dam Larsen Mar 18 '17 at 11:05
  • this is note my website i need just to create robot to do some Action always repeated can u help to change this value from console – Abdelhak Mar 18 '17 at 11:07
  • @Abdelhak To access scope from the console you can simply do some research: http://stackoverflow.com/questions/13743058/how-do-i-access-the-scope-variable-in-browsers-console-using-angularjs – cnorthfield Mar 18 '17 at 11:10
  • I have never work in this framework ( angularjs ) can u help to access and change value from console based on my code – Abdelhak Mar 18 '17 at 11:12
  • @Abdelhak you can always get the scope from an element using angular.element("#").scope, but is not a reccomend way to work with angular... you should always be using controllers to all interactions, or performance will be affected really fast... if its for testing its ok but be carefull –  Mar 18 '17 at 11:58
  • i get scope of input but how i change value and submit based on my code help me please because i don't know how to do this – Abdelhak Mar 18 '17 at 12:04
0

i solved this problem by this code

document.getElementsByName('dateeffet-annee')[0].value='2017';
    document.getElementsByName('dateeffet-mois')[0].value='12';
    var $parent = $("[name='dateeffet']");
    $parent.find("input").each(function(){
        var $this = $(this);
        angular.element($this.get(0)).triggerHandler("blur");
    });
    angular.element($parent.get(0)).scope().saveDateEffet();
Abdelhak
  • 35
  • 9