AddFormInstanceRecordMVCCommandHelper { public void updateRequiredFieldsAccordingToVisibility( ActionRequest actionRequest, DDMForm ddmForm, DDMFormValues ddmFormValues, Locale locale) throws Exception { DDMFormEvaluatorEvaluateResponse ddmFormEvaluatorEvaluateResponse = evaluate(actionRequest, ddmForm, ddmFormValues, locale); Set<String> invisibleFields = getInvisibleFields( ddmFormEvaluatorEvaluateResponse); Set<String> fieldsFromDisabledPages = getFieldNamesFromDisabledPages( ddmFormEvaluatorEvaluateResponse, getDDMFormLayout(actionRequest)); invisibleFields.addAll(fieldsFromDisabledPages); removeValue(ddmFormValues, invisibleFields); removeDDMValidationExpression( ddmForm.getDDMFormFields(), invisibleFields); List<DDMFormField> requiredFields = getRequiredFields(ddmForm); if (requiredFields.isEmpty() || invisibleFields.isEmpty()) { return; } removeRequiredProperty(invisibleFields, requiredFields); }  void updateRequiredFieldsAccordingToVisibility(
			ActionRequest actionRequest, DDMForm ddmForm,
			DDMFormValues ddmFormValues, Locale locale);  }
@Test public void testNotRequiredAndInvisibleField() throws Exception { mockDDMFormEvaluator( HashMapBuilder.<String, Object>put( "visible", false ).build()); _ddmFormField.setRequired(false); _addRecordMVCCommandHelper.updateRequiredFieldsAccordingToVisibility( _actionRequest, _ddmForm, _ddmFormValues, LocaleUtil.US); Assert.assertFalse(_ddmFormField.isRequired()); }
@Test public void testNotRequiredAndVisibleField() throws Exception { mockDDMFormEvaluator( HashMapBuilder.<String, Object>put( "visible", true ).build()); _ddmFormField.setRequired(false); _addRecordMVCCommandHelper.updateRequiredFieldsAccordingToVisibility( _actionRequest, _ddmForm, _ddmFormValues, LocaleUtil.US); Assert.assertFalse(_ddmFormField.isRequired()); }
@Test public void testRequiredAndInvisibleField() throws Exception { mockDDMFormEvaluator( HashMapBuilder.<String, Object>put( "visible", false ).build()); _addRecordMVCCommandHelper.updateRequiredFieldsAccordingToVisibility( _actionRequest, _ddmForm, _ddmFormValues, LocaleUtil.US); Assert.assertFalse(_ddmFormField.isRequired()); }
@Test public void testRequiredAndVisibleField() throws Exception { mockDDMFormEvaluator( HashMapBuilder.<String, Object>put( "visible", true ).build()); _addRecordMVCCommandHelper.updateRequiredFieldsAccordingToVisibility( _actionRequest, _ddmForm, _ddmFormValues, LocaleUtil.US); Assert.assertTrue(_ddmFormField.isRequired()); }