小编the*_*sle的帖子

AngularJS在表格内验证没有表单的输入

我的问题可能看起来很奇怪,但我建立了一个角度SPA,允许用户使用输入直接将信息输入到表中.我这样做是因为数据永远不需要在任何地方提交,并且服务使用它来计算最后显示的一些值.我现在的问题是我想验证输入以确保它们不是空的.

我做了一些研究,我找到的所有教程都依赖于输入是表单的一部分,我试图避免,因为表中的布局看起来很好并且适合目的.

        <table class="text-center">
                <tr>
                    <th class="header">Course Type</th>
                    <th>Amount of Times</th>
                    <th>Frequency (PA)</th>
                    <th>% Staff who need it</th>
                </tr>
                <tr>
                    <td class="header"><label for="induction">Induction:</label></td>
                    <td><input class="form-control" type="number" id="inductionAmount" ng-model="staff.inductionAmount" /></td>
                    <td><input class="form-control" type="number" id="inductionFrequency" ng-model="staff.inductionFrequency" /></td>   
                    <td><p>100</p></td>             
                </tr>
                <tr>
                    <td class="header"><label for="newsLetter">News letter:</label></td>
                    <td><input class="form-control" type="number" id="newsLetterAmount" ng-model="staff.newsLetterAmount" /></td>
                    <td><input class="form-control" type="number" id="newsLetterFrequency" ng-model="staff.newsLetterFrequency" /></td>
                    <td><input class="form-control" type="number" id="newsLetterPercent" ng-model="staff.newsLetterPercent" /></td>
                </tr>
       </table>

    <div class="row margin-top">
        <div class="col-sm-4 col-sm-offset-4">
            <button class="button-orange" style="font-size: 16px; font-weight: 700;" ng-click="clicked()">Next Step</button>
        </div>
    </div>  
Run Code Online (Sandbox Code Playgroud)

信息存储在一个对象中,后来用于为用户运行一些计算,建议使用角度1.2添加一些基本验证的方法,如果值为空,则不允许用户继续?对不起,这是我的第一个角度应用.我在过去使用模糊等进行了JavaScript验证,但似乎我可以使用Angular它会更简单.

javascript validation angularjs

3
推荐指数
1
解决办法
584
查看次数

量角器,失败:未知错误:无法将元素集中在自定义输入字段上

跳上测试车,现在正在实施一些网站的E2E测试,但我遇到了一个棘手的小问题.

我正在尝试选择一个字段,然后将密钥发送到该输入字段以更改值,唯一的问题是失败:未知错误:无法聚焦元素错误我似乎无法过去.我有它在其他领域工作,只是没有这个设置.

pageObject文件.

var profilePage = function() {

this.firstName = element(by.id('firstname')); 
this.lastName = element(by.id('lastname'));
this.saveBtn = element(by.css('ng-click="saveLocalAccount()"'));
this.cancelBtn = element(by.css('ng-click="cancelChanges()"'));

this.changeName = function(firstname, lastname) {

    this.firstName.click();

    var input = firstName.element(by.css('input'));
    input.click();
    this.input.sendKeys(firstname);

    this.lastName.click();
    this.lastName.sendKeys(lastname);
    browser.waitForAngular();
}
};

module.exports = new profilePage();
Run Code Online (Sandbox Code Playgroud)

规范.

var profilePage = require('TestProtractor/E2E/PageObjects/profile.pageObject.js');

describe('Testing the profile page functionality', function() {

var firstNameTest = "firstTest";
var lastNameTest = "lastTest";

it('Navigate to profile page.' ,function() {
    browser.get('xxx');

    expect(browser.getCurrentUrl())
        .toContain('xxx');
}); 

it('Should change the firstname and lastname successfully', function() { …
Run Code Online (Sandbox Code Playgroud)

javascript jquery angularjs protractor

2
推荐指数
1
解决办法
7827
查看次数

标签 统计

angularjs ×2

javascript ×2

jquery ×1

protractor ×1

validation ×1