Skip to content

Commit

Permalink
#527: forbid submitting form until notes is filled
Browse files Browse the repository at this point in the history
  • Loading branch information
riipah committed Dec 8, 2019
1 parent c60b4c7 commit f9af16e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions VocaDbWeb/App_Code/EntryDetailsHelpers.cshtml
Expand Up @@ -21,6 +21,7 @@

@helper EntryDeletePopupBase(string confirmText, string viewModelBindingName, string deleteButtonId, string title, string deleteButtonText) {

<!-- Viewmodel: DeleteEntryViewModel -->
<div style="display:none;" title="@title"
data-bind="
dialog: {
Expand All @@ -29,7 +30,7 @@
},
dialogVisible: @(viewModelBindingName).dialogVisible,
dialogButtons: [
{ text: '@deleteButtonText', click: @(viewModelBindingName).deleteEntry },
{ text: '@deleteButtonText', click: @(viewModelBindingName).deleteEntry, disabled: !@(viewModelBindingName).isValid() },
{ text: '@ViewRes.SharedStrings.Cancel', click: function() { @(viewModelBindingName).dialogVisible(false); } }
]
">
Expand All @@ -38,7 +39,7 @@
@confirmText
</p>

<textarea data-bind="textInput: @(viewModelBindingName).notes" class="input-xlarge" maxlength="200"></textarea>
<textarea data-bind="textInput: @(viewModelBindingName).notes, attr: { required: @(viewModelBindingName).notesRequired }" class="input-xlarge" maxlength="200"></textarea>

</div>

Expand Down Expand Up @@ -109,6 +110,7 @@

@helper ReportEntryPopupKnockout(string viewModelBindingName = "reportViewModel", string reportButtonId = "reportEntryLink") {

<!-- Viewmodel: ReportEntryViewModel -->
<div style="display:none;" title="@ViewRes.EntryDetailsStrings.ReportAnError"
data-bind="
with: @viewModelBindingName,
Expand Down
8 changes: 6 additions & 2 deletions VocaDbWeb/Scripts/ViewModels/DeleteEntryViewModel.ts
@@ -1,9 +1,10 @@


module vdb.viewModels {

export class DeleteEntryViewModel {

constructor(private deleteCallback: (notes: string) => void) {}
constructor(private deleteCallback: (notes: string) => void,
public readonly notesRequired: boolean = false) { }

public deleteEntry = () => {
this.dialogVisible(false);
Expand All @@ -14,6 +15,9 @@ module vdb.viewModels {

public notes = ko.observable("");

/** Report is valid to be sent (either notes are specified or not required) */
public isValid = ko.computed(() => !this.notesRequired || this.notes());

public show = () => this.dialogVisible(true);

}
Expand Down
4 changes: 2 additions & 2 deletions VocaDbWeb/Scripts/ViewModels/ReportEntryViewModel.ts
@@ -1,4 +1,4 @@


module vdb.viewModels {

export class ReportEntryViewModel {
Expand All @@ -15,7 +15,7 @@ module vdb.viewModels {

public dialogVisible = ko.observable(false);

// Report is valid to be sent (either notes are specified or not required)
/** Report is valid to be sent (either notes are specified or not required) */
public isValid: KnockoutComputed<boolean>;

public notes = ko.observable("");
Expand Down
2 changes: 1 addition & 1 deletion VocaDbWeb/Scripts/ViewModels/User/UserDetailsViewModel.ts
Expand Up @@ -54,7 +54,7 @@ module vdb.viewModels.user {
this.reportUserViewModel.notes("");
}
});
});
}, true);

public initComments = () => {

Expand Down

0 comments on commit f9af16e

Please sign in to comment.