Search code examples
meteor-autoform

Afquickfield Validation


hello guys I have a autoform quickfield. I need to enter url and if the user enter something other than url it should not allow but my validation is not working. My code is given below

  <div class="col s12">
     <label for="article-type" class="article-label">Article Source</label>
     {{> afQuickField name='url'}}
  </div>

and the field in the schema is like this

url: {
    type: String,
    optional: true,
    // label: "Article Source URL",
    autoform:{
      label: false,
      afFieldInput: {
        type: "url",
        pattern: "http://+.",
        placeholder: "Article Source URL",
      }
    }
  }

I am doing this by keeping in mind that when the field type is url the validation is applied implicitly


Solution

  • Use the regEx option.

    url: {
      type: String,
      optional: true,
      regEx: SimpleSchema.RegEx.Url,
      autoform:{
        label: false,
        afFieldInput: {
          type: "url",
          placeholder: "Article Source URL",
        }
      }
    }