Skip to content

Commit 644e8be

Browse files
committed
Disable required attributes, validators if topic is derived
If set, a topic derives all attribute values from its derived topic (indicated via an `TopicId` attribute and `DerivedTopic` property). As a result, no attribute values are mandatory except for `Key`, `ContentType`, and `ParentId`. The only one of these set via the OnTopic Editor's `Edit.cshtml` output is `Key` (_Folder Name_ in most implementations). As such, if a `DerivedTopic` is set, we use jQuery to remove the `required` attribute as well as any jQuery Validate _required_ `rules()` from all input fields, _except_ for the `Key` attribute. This effectively removed required field validation for topics that are derived, thus allowing them to potentially inherit those values from their derived topic—or, optionally, override them if the editor chooses. This fixes a new bug as of OnTopic 4.0.0 where those topics still required values, thus only allowing inheritance on optional fields. No other validators or validation attributes are impacted. As such, for instance, if a `max-length` attribute is set, that will still fire if the value is set.
1 parent 1ba3931 commit 644e8be

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

  • OnTopic.Editor.AspNetCore/Areas/Editor/Views/Editor

OnTopic.Editor.AspNetCore/Areas/Editor/Views/Editor/Edit.cshtml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@
108108
}
109109
});
110110
111+
@if (Model.Topic.DerivedTopic != null) {
112+
<text>
113+
/**
114+
* Disable required fields if derived topic, as missing values will be inherited
115+
*/
116+
$('section input, section textarea, section select')
117+
.not("section.Key input")
118+
.removeAttr('required')
119+
.rules('remove', 'required');
120+
</text>
121+
}
122+
111123
});
112124
113125
</script>

0 commit comments

Comments
 (0)