简体   繁体   English

如何生成多对数字字段和一个复选框? (复选框禁用一个数字字段)

[英]How can I generate multiple pairs of a number field and a checkbox? (checkbox disables one number field)

I'm trying to generate multiple pairs of a number form and a checkbox. 我正在尝试生成多对数字表格和一个复选框。

Clicking the checkbox disables the number field , The problem is that only the first pair is working. 单击复选框禁用数字字段问题是只有第一对在工作。 Can someone help me? 有人能帮我吗?

here's my code: addHRGrade.blade.php 这是我的代码: addHRGrade.blade.php

@extends('layouts.default')

@section('content')

<!-- opening the form -->
        {{ Form::open(array('url' => 'students/create', 'method' => 'PUT')) }}

        @foreach($students as $stud)
            <ul>
                <li>
                    <!-- Printing the students retrieved from the dataabase -->
                    {{  $stud->LName. " , " .$stud->FName }}
                    <!-- Making a text field for every students -->
                    <div ng-app="" >
                        <input name="grade" id="no_grade" type="checkbox" value="0" ng-model="checked" />
                        <label>No Grade</label>
                        <input name="grade" id="num_grade" type="number" value="65" ng-model="number" ng-disabled="checked"/>
                    </div>  
                </li>   
            </ul>
        @endforeach

        <!-- Save button -->
        <p> {{Form::submit('Save')}} </p>
        <!-- Closing the form -->
        {{ Form::close() }}

@stop

Main issue 主要问题

You're declaring one ng-app="" per table row. 您要在每个表格行中声明一个ng-app="" I don't think that's what you want to do. 我认为那不是您想要的。 You should wrap everything into a single app. 你应该一切包装成一个单一的应用程序。 Also, you don't assign anything to ngApp and also ngController so your not able to implement any further logic. 此外,您不会为ngAppngController分配任何内容,因此您将无法实现任何进一步的逻辑。

Side issues 附带问题

When you fixed the main issue, you'll see, that every checkbox and textbox will display the same value, since you assign the same model to each checkbox resp. 修复主要问题后,您会看到,每个复选框和文本框将显示相同的值,因为您为每个复选框分别指定了相同的模型。 textbox. 文本框。

The value="65" won't do anything. value="65"不会执行任何操作。 You want to display the models data, so the models data (which is undefined at startup). 您要显示模型数据,所以要显示模型数据(启动时未定义)。 To set the initial value use ng-init="number=65" . 要设置初始值,请使用ng-init="number=65"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM