Advertisement
svenpro

Untitled

May 22nd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.76 KB | None | 0 0
  1. define(
  2.     [
  3.         'jquery',
  4.         'ko',
  5.         'uiComponent',
  6.         'mage/translate'
  7.     ],
  8.     function( $, ko, Component) {
  9.         'use strict';
  10.  
  11.         return Component.extend({
  12.  
  13.             initialize: function () {
  14.                 this._super();
  15.  
  16.                 this.count = 2;
  17.                 this.removeValue = this.removeValue();
  18.             },
  19.  
  20.             //  Temporary action url
  21.             registerParticipant: function () {
  22.                 $.post(
  23.                     this.registrationUrl
  24.                 );
  25.             },
  26.  
  27.             values: ko.observableArray([{
  28.                 name: '',
  29.                 surname: '',
  30.                 email: '',
  31.                 legend: 'Participant' + ' ' + 1,
  32.                 nameAttr: 'name-attr' + '-' + 1,
  33.                 surnameAttr: 'surname-attr' + '-' + 1,
  34.                 emailAttr: 'email-attr' + '-' + 1}
  35.             ]),
  36.  
  37.             addValue: function(){
  38.                 if(this.count <= 10) {
  39.                    this.values.push({
  40.                        name: '',
  41.                        surname: '',
  42.                        email: '',
  43.                        legend: 'Participant'+ ' ' + this.count,
  44.                        nameAttr: 'name-attr' + '-' + this.count,
  45.                        surnameAttr: 'surname-attr' + '-' + this.count,
  46.                        emailAttr: 'email-attr' + '-' + this.count
  47.                    });
  48.                } else {
  49.                   $('#btnAdd').attr('disabled', 'disabled');
  50.                }
  51.                this.count += 1;
  52.                console.log(this.count);
  53.            },
  54.  
  55.            removeValue: function(){
  56.                console.log(this);
  57.                this.count -= 1;
  58.            }
  59.        });
  60.    });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement