当前位置:网站首页>Blazor University (34) forms - get form status
Blazor University (34) forms - get form status
2022-06-29 00:46:00 【Dotnet cross platform】
Link to the original text :https://blazor-university.com/forms/accessing-form-state/
Get form status
Source code [1]
Sometimes , We need to get <EditForm> Form status in the sub content . The most common use is when we need to access the input CSS Class time , Indicates whether the input is modified or valid / Invalid .
for example , If we use Bootstrap Create a with @ E-mail input control for symbol , We may end up with the following markup .
<div class="form-group">
<label for="EmailAddress">Email address</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">@@</span>
</div>
<InputText @bind-Value=MyContact.EmailAddress id="EmailAddress" class="form-control" type="email" />
</div>
</div>
However , The problem lies in , When the user enters an invalid value ,CSS Invalid class only applies to <InputText> Control .

If we want to CSS Invalid class applied to input group itself , We can use from <EditForm> Components are passed to us EditContext.
<EditForm> Of ChildContent Parameter is RenderFragment<EditContext>, It means EditContext The instance is named context The variable of ( Or we tell Blazor Any alias used ) To its internal content . For more information , Please see use RenderFragments Templated components [2].
<EditForm [email protected] Context="CurrentEditContext">
<DataAnnotationsValidator />
<div class="form-group">
<label for="EmailAddress">Email address</label>
<div class="input-group @CurrentEditContext.FieldCssClass( () => MyContact.EmailAddress)">
<div class="input-group-prepend">
<span class="input-group-text">@@</span>
</div>
<InputText @bind-Value=MyContact.EmailAddress id="EmailAddress" class="form-control" type="email" />
</div>
</div>
</EditForm>The first 1 That's ok
Use
Context=grammar , We tell Blazor Before passing in itsEditContextUse variable names whenCurrentEditContext.The first 6 That's ok
Use
EditContext.FieldCssClassMethod according to the status of the input ( modify / It works / Invalid ) Get the right CSS Class name .

If we want to , We can use some simple CSS Hide generated <input> HTML The red outline on the element .
.input-group > input.invalid
{
outline: none;
} The CSS Tell the browser , If an invalid class is applied <input> HTML The element is directly applied by input-group CSS Class HTML Element as parent element , Then the element should not have a red outline .

Reference material
[1]
Source code : https://github.com/mrpmorris/blazor-university/tree/master/src/Forms/AccessingFormState
边栏推荐
- Reference materials in the process of using Excel
- 每日一题: 数组中数字出现的次数
- 请问同花顺上开户安全吗
- Precautions for installation and use of rotary joint
- Daily question 1: the number of numbers in the array
- Is it safe to open an account on the flush
- FATAL ERROR: Could not find ./bin/my_print_defaults的解决办法
- [image detection] recognition of the front and back of a coin based on texture features with matlab code attached
- 光纤滑环价格过高的原因
- Daily English articles, reading accumulation
猜你喜欢

企业和IT领导者对创新的误解

运营级智慧校园系统源码 智慧校园小程序源码+电子班牌+人脸识别系统

Ensemble de données sur les visages masqués et méthode de génération des visages masqués

Nodejs installation and download
![[Gym 102423]-Elven Efficiency | 思维](/img/cf/b65f3db1580a83478f8351cea22040.png)
[Gym 102423]-Elven Efficiency | 思维
How does the JVM bottom layer implement synchronized

HandlerThread使用及原理

机器视觉系统的配件及工作过程

sql入门

滑环电机是如何工作的
随机推荐
Differences among VaR, let and Const
Daily practice: delete duplicates in the ordered array
Is the fund reliable and safe
What is redis
【UVM】我的 main_phase 都跑完了,为啥 case 无法退出?太不讲道理!
【架构师(第三十八篇)】 服务端开发之本地安装最新版 MySQL 数据库
PR 2021 quick start tutorial, how to use audio editing in PR?
Click hijack: X-FRAME-OPTIONS is not configured
Bug risk level
10. Yolo series
JDBC连接、断开数据库的封装
滑环的基本结构及工作原理分析
广度度优先搜索实现抓牛问题
ES6:let、const、箭头函数
How to handle a SIGTERM - how to handle a SIGTERM
Oracle uses sqlloader to prompt sql*loader-406 Import failed but no error was reported
Analysis of basic structure and working principle of slip ring
WPF 实现心电图曲线绘制
[MCU club] design of classroom number detection based on MCU [simulation design]
【leetcode】17. Letter combination of telephone number