Skip to content

Commit

Permalink
not using 'data-type' for validation
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtoroq committed Apr 20, 2023
1 parent 8a42ce4 commit 944fc8d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 43 deletions.
21 changes: 9 additions & 12 deletions schemas/xcst.rng
Original file line number Diff line number Diff line change
Expand Up @@ -634,15 +634,8 @@
<ann:documentation>A text that is displayed for this member when the value is null.</ann:documentation>
<ref name="string"/>
</attribute>
<attribute name="template">
<ann:documentation>The name of a template to use when displaying this member in a UI.</ann:documentation>
<ref name="string"/>
</attribute>
</choice>
</zeroOrMore>
<zeroOrMore docs:attrib-group="Validation">
<choice>
<attribute name="data-type">
<ann:documentation>A more specific type. Using this attribute can be a way to provide default values to the 'format' and 'template' attributes, and for using a specific input type in HTML.</ann:documentation>
<choice>
<value>CreditCard</value>
<value>Currency</value>
Expand All @@ -662,6 +655,14 @@
<value>Url</value>
</choice>
</attribute>
<attribute name="template">
<ann:documentation>The name of a template to use when displaying this member in a UI.</ann:documentation>
<ref name="string"/>
</attribute>
</choice>
</zeroOrMore>
<zeroOrMore docs:attrib-group="Validation">
<choice>
<attribute name="required">
<ann:documentation>Specifies if this member is required.</ann:documentation>
<ref name="boolean"/>
Expand Down Expand Up @@ -852,10 +853,6 @@
<define name="validation-or-member-attributes">
<zeroOrMore>
<choice>
<attribute name="data-type-message">
<ann:documentation>An error message for the data-type attribute.</ann:documentation>
<ref name="string"/>
</attribute>
<attribute name="required-message">
<ann:documentation>An error message for the required attribute.</ann:documentation>
<ref name="string"/>
Expand Down
16 changes: 7 additions & 9 deletions schemas/xcst.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,10 @@
<xs:documentation>A text that is displayed for this member when the value is null.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="template" type="c:string">
<xs:attribute name="data-type">
<xs:annotation>
<xs:documentation>The name of a template to use when displaying this member in a UI.</xs:documentation>
<xs:documentation>A more specific type. Using this attribute can be a way to provide default values to the 'format' and 'template' attributes, and for using a specific input type in HTML.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="data-type">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="CreditCard"/>
Expand All @@ -624,6 +622,11 @@
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="template" type="c:string">
<xs:annotation>
<xs:documentation>The name of a template to use when displaying this member in a UI.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="required" type="c:boolean">
<xs:annotation>
<xs:documentation>Specifies if this member is required.</xs:documentation>
Expand Down Expand Up @@ -805,11 +808,6 @@
</xs:attribute>
</xs:attributeGroup>
<xs:attributeGroup name="validation-or-member-attributes">
<xs:attribute name="data-type-message" type="c:string">
<xs:annotation>
<xs:documentation>An error message for the data-type attribute.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="required-message" type="c:string">
<xs:annotation>
<xs:documentation>An error message for the required attribute.</xs:documentation>
Expand Down
28 changes: 6 additions & 22 deletions src/Xcst.Compiler/CodeGeneration/_types.xcst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<variable name='xcst_validation_or_type_attributes' value='new[] { "validation-resource-type" }' as='string[]'/>
<variable name='xcst_validation_or_member_attributes' value='new[] {
"data-type-message", "required-message", "min-length-message", "max-length-message", "pattern-message",
"required-message", "min-length-message", "max-length-message", "pattern-message",
"range-message", "equal-to-message" }' as='string[]'/>

<variable name='xcst_type_or_member_attributes' value='new[] { "allow-empty-string", "text-member" }' as='string[]'/>
Expand Down Expand Up @@ -592,28 +592,12 @@
<call-template name='src:line-number'>
<with-param name='el' value='attr.Parent!'/>
</call-template>
<switch value='dataType'>
<when test='"EmailAddress" or "CreditCard" or "Url"'>
<code:type-reference name='{dataType}' namespace='System.ComponentModel.DataAnnotations'/>
</when>
<when test='"PhoneNumber"'>
<code:type-reference name='Phone' namespace='System.ComponentModel.DataAnnotations'/>
</when>
<otherwise>
<code:type-reference name='DataType' namespace='System.ComponentModel.DataAnnotations'/>
<code:arguments>
<code:field-reference name='{dataType}'>
<code:type-reference name='DataType' namespace='System.ComponentModel.DataAnnotations'/>
<code:arguments>
<code:field-reference name='{dataType}'>
<code:type-reference name='DataType' namespace='System.ComponentModel.DataAnnotations'/>
</code:field-reference>
</code:arguments>
</otherwise>
</switch>
<code:initializer>
<call-template name='src:validation-arguments'>
<with-param name='el' value='attr.Parent!'/>
<with-param name='name' value='attr.Name'/>
</call-template>
</code:initializer>
</code:field-reference>
</code:arguments>
</code:attribute>
</template>

Expand Down

0 comments on commit 944fc8d

Please # to comment.