Skip to content

Commit

Permalink
feat(ComponentHasModel): Criar metodo para validar propriedade [requi…
Browse files Browse the repository at this point in the history
…red]
  • Loading branch information
WilliamAguera committed May 29, 2017
1 parent eb58077 commit 5572782
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/core/base/ComponentHasModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import { ElementRef, Input } from '@angular/core';

import { ElementRef, Input, ViewChild } from '@angular/core';
import { ControlValueAccessor } from '@angular/forms';
import { ComponentCustom } from './ComponentCustom';
import { TabIndexGenerator } from '../helper/tabindex-generator';
Expand All @@ -46,6 +47,8 @@ export class ComponentHasModel extends ComponentCustom implements ControlValueAc
*/
@Input() name = '';

@ViewChild( 'inputModel' ) public inputModel;

/**
* Variable type of TabIndexGenerator in charge of instantiate a new Generator.
*/
Expand All @@ -56,6 +59,11 @@ export class ComponentHasModel extends ComponentCustom implements ControlValueAc
*/
public ngValue = '';

/**
* Text to display in Input Placeholder.
* @type {string}
*/
@Input() placeholder = '';

/**
* Function that returns value of ngModel
Expand Down Expand Up @@ -105,6 +113,14 @@ export class ComponentHasModel extends ComponentCustom implements ControlValueAc
if (value !== this.ngValue) {
this.ngValue = value;
this.onChangeCallback(this.ngValue);
this.requiredValidation();
}

}

requiredValidation() {
if (!this.inputModel.valid && this.inputModel.touched) {
this.placeholder = 'Campo Obrigatório';
}
}

Expand Down

0 comments on commit 5572782

Please sign in to comment.