We use the address field on the user profile, and expose the CRUD services of the user through the services module.
The problem: address field fails validation when a country other than the default country is submitted. "An illegal choice in <em class="placeholder">State</em> element has been detected." is the error received. This is due to the form not updating its widget something along the lines of this issue http://drupal.org/node/1861608 however that is not working in this use case when using services.
Comments
Comment #1
roam2345 commentedWe have implemented this in the mean time to work around this issue.
Comment #2
rszrama commentedI'm not sure I follow. What is there here for the Address Field module to actually do?
fwiw, I disagree with the Services philosophy of performing field CRUD using the form system; if that's what this is about, then I'd probably advise you to find some alternate method of creating / updating entities. In http://drupal.org/project/commerce_services I've created my own resource plugins for Commerce entities that will do this via a straight JSON representation of the data itself instead of trying to POST executable form data.
Comment #3
aramboyajyan commentedFor anyone who stumbles upon the same issue, I can confirm that the implementation in #1 works properly.
Here's some clarification to what issue is exactly:
- In our setup, Services are used to clone new users to another website, meaning CRUD is open for User entity.
- One of the user profile fields is using Addressfield.
- Addressfield changes country dropdown options dynamically (with an AJAX request), meaning the county dropdown is different for US and Canada.
- This causes validation issues whenever admins/users create new accounts with country other than the default one.
- This is because the services module on the receiving end has different fields for form validation, and that is where the process fails.
I am not sure where the fix should go in Addressfield module, but I hope the explanation above will help maintainers understand the issue.
Thanks!
Comment #4
eanushan commentedCan confirm. Running into the same issue. What #3 says is accurate. Default Drupal validation for select fields runs, and the county dropdown (Province/State) doesn't have the expected values for a new country.
For example, if you start out with the country being Canada, you'll have the provinces available in the county drop down (i.e Ontario, Alberta etc.)
Now if you update the user via the services module, and switch the country to United States, and then try to set the county to "Alabama", Drupal will fail the validation for the field since "Alabama" is not in the original province list of Ontario, Alberta etc.
This doesn't happen with the regular form because when you switch countries, an AJAX callback runs to fetch the new Province/State dropdown, which updates the valid select values for this drop down in the backend.
Comment #5
eanushan commentedHere is a more generic fix for all address fields, regardless of field name and entity type. It will require some code style cleanup. Place this in hook_field_widget_form_alter in any custom module.
Edit: This fix is no longer needed. The latest addressfield (7.x-1.0) fixes the issue. Including this fix will actually result in 500 errors now. Discussed and confirmed with @tyler.frankenstein.
Comment #6
damien tournoud commentedThere is nothing wrong with Entity Reference. The default resources shipped in the Services module are broken by design, because they try to use the UI forms to process API requests. Use Services Entity API instead of the default resources, or switch altogether to a better API framework like RestWS.
Comment #7
damien tournoud commentedComment #8
tyler.frankenstein commentedI've created a contrib module to help with an Address Field via Services: https://www.drupal.org/project/services_addressfield
Comment #9
aramboyajyan commentedThanks for putting up the module and posting the link here!
On another note - seems something went wrong with comment timestamps - Damien's comments are dated to October 2014 even though they were posted today/yesterday.