我们正在使用自定义策略,并在注册页面中添加了一些字段。我们有一个DateTimeDropdown声明类型,允许用户选择出生日期。以下是索赔的政策配置:
<ClaimType Id="birthDate">
<DisplayName>Birth Date</DisplayName>
<DataType>date</DataType>
<DefaultPartnerClaimTypes>
<Protocol Name="OAuth2" PartnerClaimType="birth_date" />
<Protocol Name="OpenIdConnect" PartnerClaimType="birth_date" />
<Protocol Name="SAML2" PartnerClaimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/birthdate" />
</DefaultPartnerClaimTypes>
<UserInputType>DateTimeDropdown</UserInputType>
</ClaimType>
This is how it renders on the page.
年份选择的范围从1900开始,最高可达2050.是否有任何方法可以配置更改或限制此下拉列表中的值?
这可以使用Predicates和PredicateValidations完成。更新您的ClaimType以包含PredicateValidation;
<ClaimType Id="birthDate">
<DisplayName>Birth Date</DisplayName>
<DataType>date</DataType>
<DefaultPartnerClaimTypes>
<Protocol Name="OAuth2" PartnerClaimType="birth_date" />
<Protocol Name="OpenIdConnect" PartnerClaimType="birth_date" />
<Protocol Name="SAML2" PartnerClaimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/birthdate" />
</DefaultPartnerClaimTypes>
<UserInputType>DateTimeDropdown</UserInputType>
<PredicateValidationReference Id="CustomDateRange" />
</ClaimType>
然后在</ClaimsSchema>
和<ClaimsTransformation>
之间添加以下内容;
<Predicates>
<Predicate Id="DateRange" Method="IsDateRange" HelpText="The date must be between 1920-01-01 and today.">
<Parameters>
<Parameter Id="Minimum">1920-01-01</Parameter>
<Parameter Id="Maximum">Today</Parameter>
</Parameters>
</Predicate>
</Predicates>
<PredicateValidations>
<PredicateValidation Id="CustomDateRange">
<PredicateGroups>
<PredicateGroup Id="DateRangeGroup">
<PredicateReferences>
<PredicateReference Id="DateRange" />
</PredicateReferences>
</PredicateGroup>
</PredicateGroups>
</PredicateValidation>
</PredicateValidations>