if (!field.getField().isEditable()) {
return "";
}
if (field.getField() instanceof ModelChoiceField) {
ModelChoiceField modelChoiceField = (ModelChoiceField) field.getField();
Class model = modelChoiceField.getModel();
Promptable p = (Promptable)model.getAnnotation(Promptable.class);
if (p == null) {
LogFactory.getLog(JQuerySelectWidget.class).error("Unsupported class " + model.getCanonicalName() );
return "<!-- Unsupported class " + model.getCanonicalName() + " -->";
}
//////
Object v = null;
// try to lookup the object based on the key
try {
Object fieldValue = field.getValue();
if (fieldValue instanceof String[]) {
fieldValue = ((Object[])fieldValue)[0];
}
v = fieldValue == null ? null : field.getField().clean(fieldValue.toString(), new HashMap<String, String>());
} catch (ValidationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String jqueryUrl = settings.get(JQUERY_BASEURL);
return String.format(
// hide the primary key field, create the display field and prompt icon
"$('#id_%1$s').javangoSelectWidget('%2$s','%3$s','%4$s','%5$s');\n",
field.getHtmlName(), // 1 (this is not correct..)
modelChoiceField.getModel().getCanonicalName(), // 2
v == null ? "" : v.toString(), // 3
jqueryUrl, // 4
settings.get("jquery_media_url")); // 5
}
return "";