Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Validation] - Make Identifier Optional #2579

Closed
avalanche1 opened this issue Jul 10, 2015 · 10 comments
Closed

[Validation] - Make Identifier Optional #2579

avalanche1 opened this issue Jul 10, 2015 · 10 comments
Milestone

Comments

@avalanche1
Copy link
Member

Form validation code would be DRYer if we could omit specifying field name two times.

.ui.form
  input(name='category') Select category

Instead of:

$('.ui.form').form
  fields:
    category:
      identifier: 'category'
      rules:[
        type: 'empty'
        prompt:'Specify a category']

I propose by default:

$('.ui.form').form
  fields:
    category:
      rules:[
        type: 'empty'
        prompt:'Specify a category']

In case user needs to have differing fieldname and identifier name - he can explicitly specify identifier.

@jlukic
Copy link
Member

jlukic commented Jul 10, 2015

I think this makes sense as an enhancement. Allow both

@jlukic jlukic added this to the 2.1 milestone Jul 10, 2015
@jlukic jlukic changed the title [Validation] - omit identifier [Validation] - Make Identifier Optional Jul 10, 2015
@jlukic jlukic modified the milestones: 2.2, 2.1 Aug 13, 2015
@listepo
Copy link

listepo commented Sep 11, 2015

+1

jlukic added a commit that referenced this issue Sep 13, 2015
@jlukic
Copy link
Member

jlukic commented Sep 13, 2015

Identifiers are now optional.

@jlukic
Copy link
Member

jlukic commented Sep 13, 2015

I've added a new form shorthand that works like this

$('.ui.form')
  .form({
    fields: {
      name     : 'empty',
      gender   : 'empty',
      username : 'empty',
      password : ['minLength[6]', 'empty'],
      skills   : ['minCount[2]', 'empty'],
      terms    : 'checked'
    }
  })
;

Will automatically expand out to full validation settings using default prompts and matching validation identifier against property.

@listepo
Copy link

listepo commented Sep 13, 2015

@jlukic, Thank you for your hard work

@jlukic
Copy link
Member

jlukic commented Sep 13, 2015

😄

@avalanche1
Copy link
Member Author

yay! thanks, Jack!
the next best thing for Validation would be allowing assigning the same rule to multiple fields: #667, #829

@jlukic
Copy link
Member

jlukic commented Sep 16, 2015

I was hoping to do that as well, but there are complications with how it's handled internally.

@davehayes
Copy link

Can one keep a copy of the "fields" object and alter "prompt" to change the actual error message displayed?

Alternatively can "prompt" optionally be a function that returns the error message?

@snowshine09
Copy link

It seems the shorthand version could not be used in conjunction with the full version for validation rules. It would be more reasonable to be flexible in these forms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants