我们在不同的网页/路线上有一个包含多个AutoForms的网站。如果用户触发特定表单上的验证并触发某些验证错误,然后使该表单离开页面,当他们稍后返回该页面时,他们输入的数据就会消失,但任何验证错误仍然存在(字段突出显示,显示验证错误消息。
当用户离开表单页面时,我们如何重置表单验证?
我知道我们可以使用AutoForm.resetForm('our-form-id')
进行重置,这可以在控制台中使用,但我找不到合适的挂钩来挂起它。页面的onStop
IronRouter挂钩似乎是正确的位置,但是会触发错误Can't call Tracker.flush while flushing.
如果我将其包含在setTimeout
中,超时为0,那么它就不会出现错误def start_extraction(url, output_file):
output_filepath = 'music/%s.mp3' % output_file
temp_filepath = 'temp/%s-%s.%s' % (uuid.uuid4(), output_file, '%(ext)s')
ydl_opts = {
'format': 'bestaudio/best', # choice of quality
'extractaudio' : True, # only keep the audio
'audioformat' : 'mp3', # convert to mp3
'outtmpl': temp_filepath, # name the location
'noplaylist' : True, # only download single song, not playlist
'logger': MyLogger(),
'progress_hooks': [my_hook],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
result = ydl.download([url])
#
if result == 0:
# Move the temporary file to the proper location.
shutil.move(temp_filepath, output_filepath)
return result
。 t运行到下一个滴答,它没有效果(可能是模板被那个点破坏了。)
我认为当模板被销毁时,错误状态也会如此,但事实并非如此。是否有一种无证的方式来解决问题。即使活动模板不再存在,也会重置错误?
我们正在使用AutoForm 4.2.2。
答案 0 :(得分:1)
您可以使用
重置验证public class Settings extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
Integer[] radiusArray = new Integer[]{500,700,1000,1500,2000,2500,3000,4000,5000};
Integer[] geofenceRadius = new Integer[]{100,200,300,400,500};
try {
final Spinner spinnerRA = (Spinner) findViewById(R.id.search_radius);
final Spinner spinnerGR = (Spinner) findViewById(R.id.geofence_radius);
ArrayAdapter<Integer> adapterRA = new ArrayAdapter<Integer>(this,android.R.layout.simple_spinner_item, radiusArray);
spinnerRA.setAdapter(adapterRA);
ArrayAdapter<Integer> adapterGR = new ArrayAdapter<Integer>(this,android.R.layout.simple_spinner_item, geofenceRadius);
spinnerRA.setAdapter(adapterGR);
//Getting from preference files, saved settings, if any
//1000 and 100 are default settings
final SharedPreferences sharedPref = getSharedPreferences("Settings",Context.MODE_PRIVATE);
String temp = getResources().getString(R.string.search_radius);
int savedRadius = sharedPref.getInt(temp, 1000);
temp = getResources().getString(R.string.geofence_radius);
int savedGeofence = sharedPref.getInt(temp, 100);
//Show selected value for spinner, or default value
int i;
for(i=0; i<radiusArray.length; i++){
if(radiusArray[i].equals(savedRadius)){
break;
}
}
spinnerRA.setSelection(i);
for(i=0; i<geofenceRadius.length; i++){
if(geofenceRadius[i].equals(savedGeofence)){
break;
}
}
spinnerGR.setSelection(i);
Button Save = (Button) findViewById(R.id.save_settings_button);
Save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Integer searchRadius = (Integer)spinnerRA.getSelectedItem();
Integer geofenceRadius = (Integer)spinnerGR.getSelectedItem();
//Saving new value of search_radius
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt(getString(R.string.search_radius),searchRadius);
editor.putInt(getString(R.string.geofence_radius),geofenceRadius);
editor.putBoolean(getString(R.string.initialized),true);
editor.commit();
CharSequence text = "Changes saved succesfully!";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(getApplicationContext(), text, duration);
toast.show();
}
});
}catch (Exception e){
e.printStackTrace();
}
}
答案 1 :(得分:0)
您需要使用路由器的退出挂钩来重置验证,但您必须首先获取表单的上下文。以下是它在FlowRouter中的完成方式:
FlowRouter.route('/edit/:_id', {
name: 'editPage',
action: function() {
BlazeLayout.render('appLayout', {main: 'editPage'});
},
triggersExit: [function() {
AutoForm.getValidationContext('edit-form-id').resetValidation();
}]
});
有关flowRouter触发器的更多信息,请参阅https://github.com/kadirahq/flow-router#triggers