Skip to content

Commit

Permalink
Added validation on "Price" field
Browse files Browse the repository at this point in the history
Fixed to show label on Price field appropriately when adding new record, and fixed saving of new record when currency/price are both not entered by user.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1602072
  • Loading branch information
h-kataria committed Jul 1, 2019
1 parent fcb613c commit d127bca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ def set_form_vars
@edit[:new][:zone_id] = @record.zone_id

@edit[:new][:currency] = @record.currency ? @record.currency.id : nil
@edit[:new][:code_currency] = code_currency_label(@record.currency.id) if @record.currency
@edit[:new][:code_currency] = @record.currency ? code_currency_label(@record.currency.id) : _("Price / Month")
@edit[:new][:price] = @record.price

# initialize fqnames
Expand Down Expand Up @@ -1269,7 +1269,7 @@ def get_form_vars
@available_catalogs = available_catalogs.sort # Get available catalogs with tenants and ancestors
@additional_tenants = @edit[:new][:tenant_ids].map(&:to_s) # Get ids of selected Additional Tenants in the Tenants tree

if params[:currency]
unless params[:currency].blank?
@edit[:new][:currency] = params[:currency].to_i
@edit[:new][:code_currency] = code_currency_label(params[:currency])
end
Expand Down Expand Up @@ -2016,8 +2016,14 @@ def validate_price
if @edit[:new][:currency] && @edit[:new][:price].blank?
add_flash(_("Price / Month is required"), :error)
end
add_flash(_("Price must be a numeric value"), :error) unless is_float_value(@edit[:new][:price])
end

def is_float_value(fl)
fl =~ /(^(\d+)(\.)?(\d+)?)|(^(\d+)?(\.)(\d+))/
end


def x_edit_tags_reset(db)
@tagging = session[:tag_db] = db
checked_ids = find_checked_items.empty? ? [params[:id]] : find_checked_items
Expand Down
3 changes: 3 additions & 0 deletions app/views/catalog/_st_angular_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@
"ng-model" => "vm.catalogItemModel.price",
"ng-change" => "vm.priceRequired()",
"ng-required" => "vm.priceRequired()",
"ng-pattern" => "/(^([0-9]+)(\.)?([0-9]+)?)|(^([0-9]+)?(\.)([0-9]+))/",
"maxlength" => 60,
"checkchange" => ""}
%span.help-block{"ng-show" => "vm.priceRequired()"}
= _("Required")
%span.help-block{"ng-show" => "angularForm.price.$error.pattern"}
= _("Must be a numeric value")
= render :partial => "layouts/angular/multi_tab_ansible_form_options",
:locals => {:record => @record, :ng_model => "vm.catalogItemModel"}
Expand Down

0 comments on commit d127bca

Please sign in to comment.