Skip to content

Commit 2ad2d5a

Browse files
authored
Disable Create column button while the column name is empty (#25192)
![Jun-10-2023 18-43-04](https://github.com/go-gitea/gitea/assets/80308335/4796c9be-d161-43a0-a3e3-d9cd6a19cda4) Fixes #25116
1 parent 22a39bb commit 2ad2d5a

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

templates/repo/projects/view.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
<div class="text right actions">
3636
<button class="ui cancel button">{{$.locale.Tr "settings.cancel"}}</button>
37-
<button data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}" class="ui primary button" id="new_board_submit">{{$.locale.Tr "repo.projects.column.new_submit"}}</button>
37+
<button data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}" class="ui primary button disabled" id="new_board_submit">{{$.locale.Tr "repo.projects.column.new_submit"}}</button>
3838
</div>
3939
</form>
4040
</div>

web_src/js/features/repo-projects.js

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ function updateIssueCount(cards) {
99
parent.getElementsByClassName('board-card-cnt')[0].textContent = cnt;
1010
}
1111

12+
function createNewBoard(url, boardTitle, projectColorInput) {
13+
$.ajax({
14+
url,
15+
data: JSON.stringify({title: boardTitle.val(), color: projectColorInput.val()}),
16+
headers: {
17+
'X-Csrf-Token': csrfToken,
18+
},
19+
contentType: 'application/json',
20+
method: 'POST',
21+
}).done(() => {
22+
boardTitle.closest('form').removeClass('dirty');
23+
window.location.reload();
24+
});
25+
}
26+
1227
function moveIssue({item, from, to, oldIndex}) {
1328
const columnCards = to.getElementsByClassName('board-card');
1429
updateIssueCount(from);
@@ -17,8 +32,8 @@ function moveIssue({item, from, to, oldIndex}) {
1732
const columnSorting = {
1833
issues: Array.from(columnCards, (card, i) => ({
1934
issueID: parseInt($(card).attr('data-issue')),
20-
sorting: i
21-
}))
35+
sorting: i,
36+
})),
2237
};
2338

2439
$.ajax({
@@ -31,7 +46,7 @@ function moveIssue({item, from, to, oldIndex}) {
3146
type: 'POST',
3247
error: () => {
3348
from.insertBefore(item, from.children[oldIndex]);
34-
}
49+
},
3550
});
3651
}
3752

@@ -168,24 +183,29 @@ export function initRepoProject() {
168183
});
169184
});
170185

171-
$('#new_board_submit').on('click', function (e) {
186+
$('#new_board_submit').on('click', (e) => {
172187
e.preventDefault();
173-
174188
const boardTitle = $('#new_board');
175189
const projectColorInput = $('#new_board_color_picker');
190+
if (!boardTitle.val()) {
191+
return;
192+
}
193+
const url = $(this).data('url');
194+
createNewBoard(url, boardTitle, projectColorInput);
195+
});
176196

177-
$.ajax({
178-
url: $(this).data('url'),
179-
data: JSON.stringify({title: boardTitle.val(), color: projectColorInput.val()}),
180-
headers: {
181-
'X-Csrf-Token': csrfToken,
182-
},
183-
contentType: 'application/json',
184-
method: 'POST',
185-
}).done(() => {
186-
boardTitle.closest('form').removeClass('dirty');
187-
window.location.reload();
188-
});
197+
$('.new-board').on('input keyup', (e) => {
198+
const boardTitle = $('#new_board');
199+
const projectColorInput = $('#new_board_color_picker');
200+
if (!boardTitle.val()) {
201+
$('#new_board_submit').addClass('disabled');
202+
return;
203+
}
204+
$('#new_board_submit').removeClass('disabled');
205+
if (e.key === 'Enter') {
206+
const url = $(this).data('url');
207+
createNewBoard(url, boardTitle, projectColorInput);
208+
}
189209
});
190210
}
191211

0 commit comments

Comments
 (0)