以下是我的选择框的html:
<select class=" reason_swap" id="call_type" name="call_type">
<option value=""></option>
<option title="OK - NO CHANGES" selected="" value="NC">OK - NO CHANGES</option>
<option title="OK - PENDING AUTH" value="PA">OK - PENDING AUTH</option>
<option title="OK - PENDING INS" value="IN">OK - PENDING INS</option>
<option title="OK - PENDING INS/PO" value="PI">OK - PENDING INS/PO</option>
<option title="OK - PENDING PO" value="PO">OK - PENDING PO</option></select>
我正在使用此重新聚焦功能来强制使用这三个字段。
if ($this->call_type == 'NC' && $this->times_testing == '') $this->refocus('times_testing');
if ($this->call_type == 'PA' && $this->times_testing == '') $this->refocus('times_testing');
if ($this->call_type == 'IN' && $this->times_testing == '') $this->refocus('times_testing');
我遇到的唯一问题是我只是对于如何抛出警报感到挑剔,因为只有5个选项,我警告如果五个中的三个不符合标准,我只是想要反过来做...
如果不是PI或PO而不是警告/重新聚焦帖子。
我认为这很简单......就像这样:
if (!$this->call_type == 'PI' && !$this->call_type == 'PO' && $this->times_testing == '') $this->refocus('times_testing');
但无济于事,但没有用。
非常感谢任何帮助。谢谢。
这是重新聚焦功能:
protected function refocus($name, $msg = '')
{
if (!$name) return;
$this->halt = 1;
$out = $msg ? $msg : _to_caps($name) . " is required...";
$nest = $this->nest ? $this->nest . $name : $name; // no brackets on the name here since not allowed in HTML ids
\Message::add("$out<input type='hidden' value='$nest' id='__refocus'>", 'not_ok');
}