Skip to content

Commit 392309a

Browse files
author
Seth Falcon
committed
Allow x.y as well as x.y.z in environment cookbook constraint
1 parent 72ad9ed commit 392309a

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

‎chef-server-webui/public/javascripts/cookbook_constraint_ctrl.js‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,26 @@ function populateVersionBoxContent(timestamp, cb_name){
2020

2121
function clearVersionBox(box, timestamp){
2222
populateVersionBoxContent(timestamp, retrieveCbName(timestamp));
23-
error_message = document.getElementById('inline_error_message_' + timestamp);
24-
if (error_message != null)
25-
$(error_message).remove();
23+
$('#invalid_version_error_' + timestamp).remove();
2624
}
2725

28-
function validateVersionBoxValue(box, timestamp){
26+
function validateVersionBoxValue(box, timestamp) {
2927
setTimeout(function() {
30-
if (box.value.match(/^[0-9]+\.[0-9]+\.[0-9]+$/) == null){
31-
if (box.value.length != 0 && document.getElementById('inline_error_message_' + timestamp) == null)
32-
$(box).parent().append('<span class="inline_error_message" id="inline_error_message_' + timestamp + '" >Invalid version format. The version should be in the format of x.y.z.</span>');
33-
if (box.value.length==0)
28+
var msg_class = 'invalid_version_error';
29+
var msg_id = 'invalid_version_error_' + timestamp;
30+
var xyz_match = box.value.match(/^\d+\.\d+\.\d+$/);
31+
var xy_match = box.value.match(/^\d+\.\d+$/);
32+
if (!xyz_match && !xy_match) {
33+
if (box.value.length != 0 && $('.' + msg_class).length == 0) {
34+
var error_msg = $('<div/>')
35+
.addClass(msg_class)
36+
.attr('id', msg_id).text("Version must be x.y.z or x.y");
37+
$(box).parent().append(error_msg);
38+
}
39+
if (box.value.length == 0) {
3440
box.value = "0.0.0";
35-
}
41+
}
42+
}
3643
}, 100);
3744
}
3845

‎chef-server-webui/public/stylesheets/chef.css‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,8 @@ ul.cookbook_versions{
332332
tbody.cookbook_versions td {
333333
vertical-align:top;
334334
}
335+
336+
.invalid_version_error {
337+
color: red;
338+
font-weight: bold;
339+
}

0 commit comments

Comments
 (0)