I have bee using the stepper library from https://github.com/stepstone-tech/android-material-stepper
I have already created the fragments and adapter for the stepper. It runs with no error. Each fragment has some form elements.
To validate those elements I am using AwesomeValidation library. But when I am running validate() method on validation it does not work. It is not giving any error either.
It will be very helpful if someone guides me with the right way of doing it.
Here is the code:
public class FragmentProfileBasic extends Fragment implements BlockingStep {
EditText et_fname,et_lname,et_phone,et_address,et_city,et_state,et_profile_bio,et_dob;
Spinner rel_status;
RadioGroup radioGroup;
RadioButton radioButton;
String relStatus,gender,phone,address,city,state,profile_bio,dob;
AwesomeValidation awVal;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_profile_basic, container, false);
et_fname=v.findViewById(R.id.fname);
et_lname=v.findViewById(R.id.lname);
et_phone=v.findViewById(R.id.phone);
//et_address=v.findViewById(R.id.address);
et_city=v.findViewById(R.id.city);
et_state=v.findViewById(R.id.state);
et_profile_bio=v.findViewById(R.id.profile_bio);
et_dob=v.findViewById(R.id.dob);
radioGroup = v.findViewById(R.id.radio);
awVal = new AwesomeValidation(ValidationStyle.BASIC);
awVal.addValidation(getActivity(), R.id.fname, "[a-zA-Z\\s]+", R.string.fname_error);
awVal.addValidation(getActivity(), R.id.phone, "[0-9]+", R.string.phone_error);
awVal.addValidation(getActivity(), R.id.city, "[a-zA-Z\\s]+", R.string.city_error);
awVal.addValidation(getActivity(), R.id.state, "[a-zA-Z\\s]+", R.string.state_error);
awVal.addValidation(getActivity(), R.id.profile_bio, "[a-zA-Z0-9!#@.\\s]+", R.string.covertitle_error);
//awVal.addValidation(this, R.id.profile_bio, "[a-zA-Z0-9!#@.\\s]+", R.string.bio_error);
awVal.addValidation(getActivity(), R.id.dob, "[0-9/]+", R.string.dob_error);
return v;
}
@Override
public VerificationError verifyStep() {
//return null if the user can go to the next step, create a new VerificationError instance otherwise
return null;
}
@Override
public void onSelected() {
//update UI when selected
}
@Override
public void onError(@NonNull VerificationError error) {
//handle error inside of the fragment, e.g. show error on EditText
}
@Override
public void onNextClicked(StepperLayout.OnNextClickedCallback callback) {
if(awVal.validate()) {
callback.goToNextStep();
}
}
@Override
public void onCompleteClicked(StepperLayout.OnCompleteClickedCallback callback) {
callback.complete();
}
@Override
public void onBackClicked(StepperLayout.OnBackClickedCallback callback) {
}
}
onNextClickedmethod. You can use any validator plugin or you can check if the input or control is empty. - Imustech S