Changes
Title
unchanged
Updating fields on a form with Ajax and Json
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
AJAX, SOAP, JSON, calculated fields, form
Content
changed
[...]
Yii::app()->end();
}
catch (SoapFault $soapFault)
{
// Theres a problem with SOAP
// or the enquire() function threw an error, an invalid registristration number for example
$status = 'HPI Error : ' . substr($soapFault->faultcode, strlen('soapenv:'));
$status .= ' (' . $soapFault->detail->HpiSoapFault->Error->Code . ') ';[...]
// Data to be passed to the ajax function
// Note that the ' should be escaped with \
// The field id should be prefixed with the model name eg Vehicle_field_name
'data'=>array('registration_number'=>'js:$(\'#Vehicle_registration_number\').val()',[...]
// Then change the selected option
$('#Vehicle_vehicle_colour_id').val(data.colour_id);
if (data.makeOption!='') $('#Vehicle_vehicle_make_id').append(data.makeOption);
$('#Vehicle_vehicle_make_id').val(data.make_id);
if (data.modelOption
!='') $('#Vehicle_vehicle_model_id').append(data.modelOption);
$('#Vehicle_vehicle_model_id').val(data.model_id);
}
} ",
))?>;[...]