Skip to content

Commit

Permalink
Add verification that name is not taken or nul
Browse files Browse the repository at this point in the history
  • Loading branch information
ZitaNemeckova committed Jul 2, 2019
1 parent 0d3e4f6 commit 2cf99cd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,17 @@ def servicetemplate_copy_cancel
replace_right_cell
end

def servicetemplate_copy_saved()
def servicetemplate_copy_saved
add_flash(_("Copy of a Service Catalog Item was successfully saved"))
@sb[:action] = @edit = @record = nil
@in_a_form = false
replace_right_cell
end

def servicetemplates_names
render :json => {:names => ServiceTemplate.all.pluck(:name)}
end

def atomic_st_edit
# reset the active tree back to :sandt_tree, it was changed temporairly to display automate entry point tree in a popup div
self.x_active_tree = 'sandt_tree'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import { componentTypes } from '@data-driven-forms/react-form-renderer';
import debouncePromise from '../../helpers/promise-debounce';
import { http } from '../../http_api';

export const asyncValidator = value =>
http.get('/catalog/servicetemplates_names')
.then((json) => {
if (json.names.includes(value)) {
return __('Name has already been taken');
}
if (value === '' || value === undefined) {
return __("Name can't be blank");
}
return undefined;
});
const asyncValidatorDebounced = debouncePromise(asyncValidator);

function createSchema() {
const fields = [
{
component: componentTypes.TEXT_FIELD,
name: 'name',
validate: [
value => asyncValidatorDebounced(value),
],
label: __('Name'),
maxLength: 40,
}];
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@
ot_edit
ot_orchestration_managers
ot_show
servicetemplates_names
show
),
:post => %w(
Expand Down

0 comments on commit 2cf99cd

Please sign in to comment.