required 相关问题

必需是输入元素的HTML属性,强制提供输入。

为什么当我点击不相关按钮时显示“请填写此字段”验证消息

我在页面上使用了地图,当我单击“cellSize”按钮时,会出现填充字段警告。我不想这样。如何解决这个问题? 像这样的警告: 这是我的文本字段: 我在页面上使用了地图,当我单击“cellSize”按钮时,会出现填充字段警告。我不想这样。如何解决这个问题? 这样的警告: 这是我的文本字段: <div class="form-group"> <label for="name">Name</label> <input ng-model="Name" ng-readonly="view.readonly" ng-maxlength="100" type="text" class="form-control input-sm" id="cluster-name" placeholder="Name" required> </div> 这是我的增量按钮点击: change: function () { this.trigger("spin"); $scope.cellSizeCoefficient = this.value(); $scope.$broadcast('mapCellSizeChanged', $scope.map); $.each($scope.cellShapes, function (index, cellShape) { var radius = getRadius(cellShape.Cell); cellShape.Circle.setRadius(radius); if (cellShape.Circle.label) { var labelLoc = findLocationAtDistanceFrom(cellShape.Cell.LOC, cellShape.Cell.AZ, radius); cellShape.Circle.label.setLatLng([labelLoc.Y, labelLoc.X]); } }); if (selectedCellCircle) { var radius = getRadius(selectedCellCircle.Cell) + 50; selectedCellCircle.setRadius(radius); } } 由于输入元素上的 required 属性,您会看到该消息。当单击“增量”按钮时提交 form 时会显示它。 要停止该行为,请将 type="button" 属性添加到 button: <button type="button" style="margin-left:2px;" kendo-button="btnCellSizeIncrement" k-options="btnCellSizeIncrementOptions"> <i class="fa fa-plus pi-icon pi-icon-plus"></i> </button> 仅供参考,您应该在任何您不想要在单击时提交 type="button" 的 button 元素上添加 form 属性。 如果不是必填字段,请从此 HTML 中删除 required 属性,否则浏览器将在表单提交时显示此消息。确保您在单击单元格大小按钮时没有提交表单。 <input ng-model="Name" ng-readonly="view.readonly" ng-maxlength="100" type="text" class="form-control input-sm" id="cluster-name" placeholder="Name" required> 添加 novalidate 和表单标签作为必需属性,以便触发 HTML5 验证。 <form novalidate> <div class="form-group"> <label for="name">Name</label> <input ng-model="Name" ng-readonly="view.readonly" ng-maxlength="100" type="text" class="form-control input-sm" id="cluster-name" placeholder="Name" required> </div> </form> 我有一个按钮导致了同样的行为,当我不想要它时触发表单验证。我的按钮交换了一些表单字段。解决方案很简单:我没有将按钮定义为具有 onclick 事件的输入元素,而是将其更改为具有 onclick 事件的 img 元素。该按钮作用于表单,它不是表单的一部分,我认为与您的表单相同。

回答 4 投票 0

Laravel 验证不会显示

我有一个类型为“number”的数字输入,我给它一个该等级输入的验证错误(nilai): ... 我有一个带有 type="number" 的数字输入,我为此等级输入给出了一个验证错误(nilai): <div class="col-4"> <div class="form-group"> <label>Nilai <span class="text-danger">*</span></label> <input type="number" id="grade" name="grade[]" class="form-control @error('grade') is-invalid @enderror" placeholder="Masukkan nilai" required> @if (count($errors) > 0) @error('grade') <div class="invalid-feedback">{{ $message }}</div> @enderror @else <div class="invalid-feedback">Mohon isikan nilai</div> @endif </div> </div> 这是控制器中的验证器: $request->validate( [ 'student_id' => 'required|integer', 'nis' => 'required|integer', 'class' => 'required|string', 'major' => 'required|not_in:0', 'attitude_point' => 'required|array', 'attitude_point.*' => 'integer', 'competency_point' => 'required|array', 'competency_point.*' => 'string', 'grade' => 'required|array', 'grade.*' => 'integer', 'predicate' => 'required|array', 'predicate.*' => 'string', ], [ 'student_id.required' => 'The student name field is required.', 'grade.required' => 'The grade field is required.', ] ); 问题是,其他输入工作正常: 它应该显示类似“成绩字段是必填字段”的消息。 我尝试将验证更改为'numeric'或'integer|digits_between:0,100',但不起作用。我想知道出了什么问题。 不应使用 'grade.*' => 'integer',而应使用 'grade.*' => 'required|integer' 来确保数组中的每个元素都存在并且是整数。

回答 1 投票 0

将必需的属性应用于复选框

我们可以将必需的属性应用于html多个复选框中的复选框吗?而不使用javascript或jquery 我想在没有 javascript 的情况下对 html 页面应用验证。并且还会显示警告消息。

回答 2 投票 0

如何处理 C# 中的“必需成员必须在对象初始化程序或属性构造函数中设置”错误

我有两个班级 - 州 - 校长班级和学区家属班级。 公共类状态 { 公共 int StateId { 获取;放; } 公共必需的字符串 StateName { get;放; } 公开

回答 1 投票 0

我想将必填字段符号(星号)的颜色更改为红色

我想将必填字段符号(星号)的颜色更改为红色。我正在使用 Mud-Blazor。我使用下面的代码尝试了它。这是我应用代码后的图像这是我正在使用的代码...

回答 1 投票 0

我的表单中有两个必填字段。我希望星号颜色应该是红色。目前它显示为黑色

我的表单中有两个必填字段。我希望星号颜色应为红色。目前它显示为黑色。我正在使用 Mudblazor。 我尝试了多种方式但没有得到输出。请让...

回答 1 投票 0

在 Angular 中动态更改选择字段的验证

我的 Angular 应用程序遇到问题,在提交表单后,我动态更改表单中选择字段的必需属性。 评估.component.html <...

回答 1 投票 0

`必需`属性和 EF Core

一年前,C#版本。 11、添加了所需的修饰符。因此,如果我们按要求标记属性,如下所示: 公开课点 { 公共要求 int X { get;放; } 公共要求 int Y { ge...

回答 0 投票 0

C# 解决警告编译“CS8618”的最佳方法是什么

如果我们像这样声明属性: 公开课猫 { 公共字符串名称{获取;放; } } 我们收到警告编译: CS8618 - 不可为空变量必须包含非空值 退出

回答 1 投票 0

为什么必需的属性在表单上不起作用?

我正在创建此表单,但是当我单击“创建任务”按钮时,所需的属性将被忽略。 我正在使用 innerHTML 和创建表单: 我正在创建此表单,但是当我单击“创建任务”按钮时,所需的属性将被忽略。 我正在使用innerHTML 创建表单,并且: <form id="task-form"> <label for="task-title">Title:</label> <input type="text" id="task-title" name="task-title" required> <label for="task-date">Due date:</label> <input type="date" id="task-date" name="task-date" required> <label for="task-description">Description:</label> <textarea name="task-description" id="task-description" required></textarea> <label for="checkbox">Add to a project?</label> <input type="checkbox" name="checkbox" id="checkbox"> <label for="task-priority">Priority:</label> <select name="task-priority" id="task-priority" required> <option value="Low">Low</option> <option value="Medium">Medium</option> <option value="High">High</option> </select> <button type="submit" id="create-task-btn">Create Task</button> </form>``` Also the console give me one warning saying: "Form submission canceled because the form is not connected" 因为您要动态添加创建侦听器所需的表单 // Create the form element and set its properties const form = document.createElement('form'); form.id = 'task-form'; // Create and append the form's content form.innerHTML = ` <label for="task-title">Title:</label> <input type="text" id="task-title" name="task-title" required> <label for="task-date">Due date:</label> <input type="date" id="task-date" name="task-date" required> <label for="task-description">Description:</label> <textarea name="task-description" id="task-description" required></textarea> <label for="checkbox">Add to a project?</label> <input type="checkbox" name="checkbox" id="checkbox"> <label for="task-priority">Priority:</label> <select name="task-priority" id="task-priority" required> <option value="Low">Low</option> <option value="Medium">Medium</option> <option value="High">High</option> </select> <button type="submit" id="create-task-btn">Create Task</button> `; // Append the form to the document const formContainer = document.getElementById('form-container'); formContainer.appendChild(form); // Add an event listener for form submission form.addEventListener('submit', function (event) { event.preventDefault(); // Prevent the default form submission behavior // Your form submission logic here }); <div id="form-container"></div>

回答 1 投票 0

有没有办法以角度有条件地设置所需的输入?

我想要实现的是仅在给出另一个输入时才需要组件/指令输入,例如: @Input() 名称!:字符串; @Input({ required: name!!}) surname!:string; 这是吗

回答 2 投票 0

根据需要通过 JavaScript 以模型驱动应用程序的形式定义可编辑网格内的字段

我想根据需要以与模型驱动应用程序相同的形式在多个可编辑网格中定义多个列。这背后的意义是,我们有 2 个不同的模型驱动应用程序,用于 2 个差异......

回答 2 投票 0

jsonschema 验证所需和/或有条件需要的属性

我需要验证一个始终具有 2 个属性的 json 对象: 类型 姓名 类型可以是“A”、“B”或“C”, 当类型为“A”时,属性“foo”也是必需的,并且没有其他属性可供使用...

回答 3 投票 0

playwright-test:测试是否需要输入

我需要输入登录表单: 我需要输入登录表单: <input autoComplete="email" defaultValue={email} disabled={state === 'submitting'} id="email" name="email" placeholder={t('user-authentication:email-placeholder')} required // HERE! type="email" /> 如何测试 Playwright 是否需要输入?我在 Chromium 中的本机浏览器警告是:“请填写此字段。” 有没有办法在 Playwright 中检查/断言此警告?或者另一种方法来测试是否需要输入? 我尝试使用 .fill('') 在输入中不写入任何内容,然后使用 page.keyboard.press('Enter') 按 Enter 键,但这些并没有导致出现警告。 如果消息是由浏览器显示的,而不是添加到 DOM 中的内容,那么您将很难直接在 Playwright 中测试它。 您可以检查 required 属性是否存在,并相信浏览器将显示警告。 await page.locator('input#email[required]') 还有一个约束验证您可以应用 如果该元素是必需的,并且该元素的值为空字符串,则该元素将遭受 valueMissing 的影响,并且该元素将匹配 :invalid 伪类。 await page.locator('input#email[required]:invalid') 可以但不建议测试。这是工作代码: import { expect, test} from '@playwright/test'; test('has error message presented', async ({ page }) => { await page.goto('https://q94u5.csb.app/'); const email = page.getByRole('textbox') const submit = page.getByRole('button', { name: 'Submit' }); await email.fill('x'); await submit.click(); const error = page.locator('input:invalid'); const validationMessage = await error.evaluate((element) => { const input = element as HTMLInputElement return input.validationMessage }) expect(validationMessage).toContain("Please include an '@' in the email address. 'x' is missing an '@'.") }); 在此处阅读有关内置验证的更多信息: https://www.w3.org/WAI/tutorials/forms/validation/

回答 2 投票 0

Angular Material 单选按钮组需要验证不起作用

我试图在用户单击“提交”时验证单选按钮组。文本字段和下拉列表在无效时显示红色,但单选按钮颜色在无效时不会更改。有什么建议吗?...

回答 2 投票 0

如何通过反射读取C# 11中所需的属性

在 C# 11 中,Microsoft 引入了字段和属性所需的属性作为类的成员。 我需要在反射中读取这个属性。我该怎么做? 例如,在 C1 类和 P1 属性中...

回答 1 投票 0

如何通过反射读取c# 11中的required属性

在 c# 11 中,微软确定字段和属性所需的属性作为类的成员。 我们需要在反射中读取这个属性。我该怎么办? 例如在 C1 类和 prope...

回答 1 投票 0

Mobile Safari 上的 HTML 表单“必需”属性不起作用

iPad 上的 Mobile Safari 应该兼容 HTML5,但似乎 required 属性不起作用。任何人都知道为什么,或者有一个不需要大量 JavaScript 的不错的解决方法......

回答 6 投票 0

尝试提交表单而不填写必填字段时如何获得提示? (不适用于 Firefox 移动版)

在 Firefox 移动版中提交表单而不填写必填字段时,我没有收到提示,显示缺少哪个字段。在 Windows 上的 Firefox 和 Android 上的 Chrome 中,我得到了一个工具...

回答 1 投票 0

需要 Visual Basic 下拉字段

在word中制作表格时,是否有代码可以使下拉列表成为必填字段。我有代码使自由文本字段成为必填字段,但没有下拉列表。以下是我的免费文本 子

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.