��权限没有,则隐藏 function forum_list_access_filter($forumlist, $gid, $allow = 'allowread') { global $grouplist; if (empty($forumlist)) return array(); if (1 == $gid) return $forumlist; $forumlist_filter = $forumlist; $group = $grouplist[$gid]; foreach ($forumlist_filter as $fid => $forum) { if (empty($forum['accesson']) && empty($group[$allow]) || !empty($forum['accesson']) && empty($forum['accesslist'][$gid][$allow])) { unset($forumlist_filter[$fid]); } unset($forumlist_filter[$fid]['accesslist']); } return $forumlist_filter; } function forum_filter_moduid($moduids) { $moduids = trim($moduids); if (empty($moduids)) return ''; $arr = explode(',', $moduids); $r = array(); foreach ($arr as $_uid) { $_uid = intval($_uid); $_user = user_read($_uid); if (empty($_user)) continue; if ($_user['gid'] > 4) continue; $r[] = $_uid; } return implode(',', $r); } function forum_safe_info($forum) { //unset($forum['moduids']); return $forum; } function forum_filter($forumlist) { foreach ($forumlist as &$val) { unset($val['brief'], $val['announcement'], $val['seo_title'], $val['seo_keywords'], $val['create_date_fmt'], $val['icon_url'], $val['modlist']); } return $forumlist; } function forum_format_url($forum) { global $conf; if (0 == $forum['category']) { // 列表URL $url = url('list-' . $forum['fid'], '', FALSE); } elseif (1 == $forum['category']) { // 频道 $url = url('category-' . $forum['fid'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = url('read-' . trim($forum['brief']), '', FALSE); } if ($conf['url_rewrite_on'] > 1 && $forum['well_alias']) { if (0 == $forum['category'] || 1 == $forum['category']) { $url = url($forum['well_alias'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = ($forum['threads'] && $forum['brief']) ? url($forum['well_alias'] . '-' . trim($forum['brief']), '', FALSE) : url($forum['well_alias'], '', FALSE); } } return $url; } function well_forum_alias() { $forumlist = forum_list_cache(); if (empty($forumlist)) return ''; $key = 'forum-alias'; static $cache = array(); if (isset($cache[$key])) return $cache[$key]; $cache[$key] = array(); foreach ($forumlist as $val) { if ($val['well_alias']) $cache[$key][$val['fid']] = $val['well_alias']; } return array_flip($cache[$key]); } function well_forum_alias_cache() { global $conf; $key = 'forum-alias-cache'; static $cache = array(); // 用静态变量只能在当前 request 生命周期缓存,跨进程需要再加一层缓存:redis/memcached/xcache/apc if (isset($cache[$key])) return $cache[$key]; if ('mysql' == $conf['cache']['type']) { $arr = well_forum_alias(); } else { $arr = cache_get($key); if (NULL === $arr) { $arr = well_forum_alias(); !empty($arr) AND cache_set($key, $arr); } } $cache[$key] = empty($arr) ? '' : $arr; return $cache[$key]; } ?>javascript - make angular ng-if reserve space for showing if event occurs - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - make angular ng-if reserve space for showing if event occurs - Stack Overflow

programmeradmin5浏览0评论

I have a set up in which I am having a modal form for some details to be submitted. But when one of the text-field is put blank - generating a label below the text-field saying "it is required" causes "Proceed" button to move - (Infact all others below it to move). How can make DOM to reserve space for such labels - while I am using ng-if of angularjs.

My question visually is shown in below image

code is as follows:

<div class="col-md-5">
    <input type="text" name="userFirstName" ng-model="registerAppCtrl.registerAppDetails.user.fn" id="reg-fname" class="form-control" tabindex="1" placeholder="First Name" autofocus required/> 
    <div class="error-help">
        <p ng-if="customerDetailsForm.userFirstName.$invalid && !customerDetailsForm.userFirstName.$pristine">First name is required</p>
    </div>
								
    <input type="email" name="userEmailId" ng-model="registerAppCtrl.registerAppDetails.user.email" id="reg-email" class="form-control" tabindex="3"  placeholder="E-mail ID" required/>
    <div class="error-help">
        <p ng-if="customerDetailsForm.userEmailId.$error.required && !customerDetailsForm.userEmailId.$pristine">Email ID is required</p>
        <p ng-if="customerDetailsForm.userEmailId.$dirty && customerDetailsForm.userEmailId.$error.email" ng-hide="customerDetailsForm.userEmailId.$pristine">Email ID is invalid</p>
    </div>
    <input type="text" name="userName" ng-model="registerAppCtrl.registerAppDetails.user.uname" id="reg-uname" class="form-control" tabindex="5"  placeholder="User Name" onkeyup="unameAvailability($(this).val())" required/>
    <span id="uname-check" style="opacity: 0;"><i class="fa"></i><i id="avail-message"></i></span>
</div>
								
<div class="col-md-5 col-md-offset-1">
    <input type="text" name="userLastName" ng-model="registerAppCtrl.registerAppDetails.user.ln" id="reg-lname" class="form-control"  tabindex="2" placeholder="Last Name" required/>
    <div class="error-help">
        <p ng-if="customerDetailsForm.userLastName.$invalid && !customerDetailsForm.userLastName.$pristine">Last name is required</p>
    </div> 
<input type="number" name="userPhoneNo" ng-model="registerAppCtrl.registerAppDetails.user.phone" id="reg-phone" class="form-control" tabindex="4" placeholder="Phone" required/>
<div class="error-help">
    <p ng-if="customerDetailsForm.userPhoneNo.$invalid && !customerDetailsForm.userPhoneNo.$pristine">Phone number is required</p>
</div> 
								
<input type="password" name="userPassword" ng-model="registerAppCtrl.registerAppDetails.user.pass" id="reg-pwd" class="form-control" tabindex="6" placeholder="Password" required/>
    <div class="error-help">
        <p ng-if="customerDetailsForm.userPassword.$invalid && !customerDetailsForm.userPassword.$pristine">Password is required</p>
    </div>
</div>
<div class="col-md-12">
    <button class="btn btn-proceed1"  tabindex="7"  ng-disabled="customerDetailsForm.$invalid" ng-click="registerAppCtrl.fadeProceed('tab1', 'tab2');" style="position: fixed;" >Proceed</button>
</div>	

I have a set up in which I am having a modal form for some details to be submitted. But when one of the text-field is put blank - generating a label below the text-field saying "it is required" causes "Proceed" button to move - (Infact all others below it to move). How can make DOM to reserve space for such labels - while I am using ng-if of angularjs.

My question visually is shown in below image

code is as follows:

<div class="col-md-5">
    <input type="text" name="userFirstName" ng-model="registerAppCtrl.registerAppDetails.user.fn" id="reg-fname" class="form-control" tabindex="1" placeholder="First Name" autofocus required/> 
    <div class="error-help">
        <p ng-if="customerDetailsForm.userFirstName.$invalid && !customerDetailsForm.userFirstName.$pristine">First name is required</p>
    </div>
								
    <input type="email" name="userEmailId" ng-model="registerAppCtrl.registerAppDetails.user.email" id="reg-email" class="form-control" tabindex="3"  placeholder="E-mail ID" required/>
    <div class="error-help">
        <p ng-if="customerDetailsForm.userEmailId.$error.required && !customerDetailsForm.userEmailId.$pristine">Email ID is required</p>
        <p ng-if="customerDetailsForm.userEmailId.$dirty && customerDetailsForm.userEmailId.$error.email" ng-hide="customerDetailsForm.userEmailId.$pristine">Email ID is invalid</p>
    </div>
    <input type="text" name="userName" ng-model="registerAppCtrl.registerAppDetails.user.uname" id="reg-uname" class="form-control" tabindex="5"  placeholder="User Name" onkeyup="unameAvailability($(this).val())" required/>
    <span id="uname-check" style="opacity: 0;"><i class="fa"></i><i id="avail-message"></i></span>
</div>
								
<div class="col-md-5 col-md-offset-1">
    <input type="text" name="userLastName" ng-model="registerAppCtrl.registerAppDetails.user.ln" id="reg-lname" class="form-control"  tabindex="2" placeholder="Last Name" required/>
    <div class="error-help">
        <p ng-if="customerDetailsForm.userLastName.$invalid && !customerDetailsForm.userLastName.$pristine">Last name is required</p>
    </div> 
<input type="number" name="userPhoneNo" ng-model="registerAppCtrl.registerAppDetails.user.phone" id="reg-phone" class="form-control" tabindex="4" placeholder="Phone" required/>
<div class="error-help">
    <p ng-if="customerDetailsForm.userPhoneNo.$invalid && !customerDetailsForm.userPhoneNo.$pristine">Phone number is required</p>
</div> 
								
<input type="password" name="userPassword" ng-model="registerAppCtrl.registerAppDetails.user.pass" id="reg-pwd" class="form-control" tabindex="6" placeholder="Password" required/>
    <div class="error-help">
        <p ng-if="customerDetailsForm.userPassword.$invalid && !customerDetailsForm.userPassword.$pristine">Password is required</p>
    </div>
</div>
<div class="col-md-12">
    <button class="btn btn-proceed1"  tabindex="7"  ng-disabled="customerDetailsForm.$invalid" ng-click="registerAppCtrl.fadeProceed('tab1', 'tab2');" style="position: fixed;" >Proceed</button>
</div>	

Share Improve this question edited May 24, 2017 at 7:08 li0n_za 4552 silver badges15 bronze badges asked May 24, 2017 at 7:01 nightfurynightfury 4127 silver badges19 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

You can reserve space by using another <p> element in your case using ng-hide and visibility:hidden; :

<div class="error-help">
    <p ng-if="customerDetailsForm.userPhoneNo.$invalid &&!customerDetailsForm.userPhoneNo.$pristine">Phone number is required</p>

    <p style="visibility:hidden;" ng-hide="customerDetailsForm.userPhoneNo.$invalid &&!customerDetailsForm.userPhoneNo.$pristine" >Phone number is required</p>

</div> 

My suggestion is more of a workaround. You can replace ng-if with ng-class. You can give your errors a class based on your conditions - for example invisible. In the CSS you will define the invisible class as:

.invisible {
    visibility: hidden;
}

managed to do it using [ngStyle]

[ngStyle]="{'visibility': my-flag ? 'visible' : 'hidden'}"
发布评论

评论列表(0)

  1. 暂无评论