如果选中了复选框,则需要在输入字段中进行验证

时间:2020-07-25 10:56:02

标签: javascript php jquery jquery-validate

我有一个from,其中存在一些复选框以及与之相关的复选框,输入字段。如果我选择任何复选框,则输入字段出现,然后我必须填写该输入字段。如果未填写输入字段,则选中了该复选框,则应显示必需消息。

我的代码是:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spawner : MonoBehaviour
{
    public GameObject[] spawnableItems;

    // Update is called once per frame
    void Update()
    {
        bool isTimeToSpawn (GameObject itemGameObject)
        {
            spawnableSprites item = itemGameObject.GetComponent<spawnableSprites>();
            float spawnDelay = item.seenEverySeconds;
            float spawnsPerSecond = 1 / spawnDelay;

            if(Time.deltaTime > spawnDelay)
            {
                Debug.LogWarning("SpawnRate Capped By FrameRate");
            }
            float threshold = spawnsPerSecond * Time.deltaTime;

            if(Random.value < threshold)
            {
                return true;
            }

            else
            {
                return false;
            }

        }


        foreach (GameObject item in spawnableItems)
        {
            if(isTimeToSpawn(item))
            {
                Spawn(item);
            }
        }
    }

    void Spawn (GameObject myGameObject)
    {
        GameObject myItem = Instantiate(myGameObject) as GameObject;
        myItem.transform.parent = transform;
        myItem.transform.position = transform.position;
    }
}

jquery是:

  <form id="submit_form" action="#" method="POST" autocomplete="off">
  <?php 
  $result = $obj->show_social_icons();
  foreach($result as $key => $row)
  {
  ?>
   <div class="form-group col-md-12 col-sm-12 col-xs-12 heightauto">
    <input type="checkbox" class="maxtickets_enable_cb" <?php if(isset($_SESSION['checkbox']) && ($_SESSION['checkbox'] != '')) { if(in_array($row['id'],$_SESSION['checkbox'])) {?> checked="checked" <?php } else{ echo ""; } }?> name="opwp_wootickets[]" value="<?php echo $row['id']; ?>"><?php echo $row['name']; ?>

     <div class="max_tickets">
      <input type="text" name="link[]" value="<?php if(isset($_SESSION['link']) && ($_SESSION['link'] != '')) { echo $_SESSION['link'][$key]; } ?>" placeholder="<?php echo $row['placeholder']; ?>" class="form-control validatethis">
  </div>
  </div>
  <?php } ?>
   <button type="submit" href="#" name="social_submit" class="next_button">Preview</button>
   </form>

enter image description here

验证仅适用于第一行。在上面的代码中,如果我填写了第一个复选框输入字段,然后再次选中其他复选框并清空了该输入字段,则表单提交了。如何在所有选中的复选框输入字段中应用验证?

0 个答案:

没有答案
相关问题