from flask.ext.wtf import Form
from wtforms.fields import FloatField, StringField, SubmitField
from wtforms.validators import InputRequired, Length


class SingleResourceForm(Form):
    name = StringField('Name', validators=[
        InputRequired(),
        Length(1, 500)
    ])
    address = StringField('Address', validators=[
        InputRequired(),
        Length(1, 500)
    ])
    latitude = FloatField('Latitude', validators=[
        InputRequired()
    ])
    longitude = FloatField('Longitude', validators=[
        InputRequired()
    ])
    submit = SubmitField('Save Resource')

from flask.ext.wtf import Form
from wtforms.fields import FloatField, StringField, SubmitField
from wtforms.validators import InputRequired, Length, Optional


class SingleResourceForm(Form):
    name = StringField('Name', validators=[
        InputRequired(),
        Length(1, 500)
    ])
    address = StringField('Address', validators=[
        InputRequired(),
        Length(1, 500)
    ])
    latitude = FloatField('Latitude', validators=[
        Optional()
    ])
    longitude = FloatField('Longitude', validators=[
        Optional()
    ])
    submit = SubmitField('Save Resource')

    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False
        if not self.latitude.data or not self.longitude.data:
            self.address.errors.append('Please select a valid address')
            return False
        return True

Add validator if latitude/longitude is empty
Add validator if latitude/longitude is empty

  from flask.ext.wtf import Form
  from wtforms.fields import FloatField, StringField, SubmitField
- from wtforms.validators import InputRequired, Length
+ from wtforms.validators import InputRequired, Length, Optional
  
  
  class SingleResourceForm(Form):
      name = StringField('Name', validators=[
          InputRequired(),
          Length(1, 500)
      ])
      address = StringField('Address', validators=[
          InputRequired(),
          Length(1, 500)
      ])
      latitude = FloatField('Latitude', validators=[
-         InputRequired()
+         Optional()
      ])
      longitude = FloatField('Longitude', validators=[
-         InputRequired()
+         Optional()
      ])
      submit = SubmitField('Save Resource')
  
+     def validate(self):
+         rv = Form.validate(self)
+         if not rv:
+             return False
+         if not self.latitude.data or not self.longitude.data:
+             self.address.errors.append('Please select a valid address')
+             return False
+         return True
+ 
Add validator if latitude/longitude is empty
## Code Before:
from flask.ext.wtf import Form
from wtforms.fields import FloatField, StringField, SubmitField
from wtforms.validators import InputRequired, Length


class SingleResourceForm(Form):
    name = StringField('Name', validators=[
        InputRequired(),
        Length(1, 500)
    ])
    address = StringField('Address', validators=[
        InputRequired(),
        Length(1, 500)
    ])
    latitude = FloatField('Latitude', validators=[
        InputRequired()
    ])
    longitude = FloatField('Longitude', validators=[
        InputRequired()
    ])
    submit = SubmitField('Save Resource')

## Instruction:
Add validator if latitude/longitude is empty
## Code After:
from flask.ext.wtf import Form
from wtforms.fields import FloatField, StringField, SubmitField
from wtforms.validators import InputRequired, Length, Optional


class SingleResourceForm(Form):
    name = StringField('Name', validators=[
        InputRequired(),
        Length(1, 500)
    ])
    address = StringField('Address', validators=[
        InputRequired(),
        Length(1, 500)
    ])
    latitude = FloatField('Latitude', validators=[
        Optional()
    ])
    longitude = FloatField('Longitude', validators=[
        Optional()
    ])
    submit = SubmitField('Save Resource')

    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False
        if not self.latitude.data or not self.longitude.data:
            self.address.errors.append('Please select a valid address')
            return False
        return True
