(name, data, valid_func, preprocess_func, clear_invalid=False)
| 281 | |
| 282 | |
| 283 | def check_item(name, data, valid_func, preprocess_func, clear_invalid=False): |
| 284 | try: |
| 285 | data = preprocess_func(data) |
| 286 | error_msg = valid_func(data) |
| 287 | except Exception as e: |
| 288 | logger.warning('Get %r in valid_func for name:"%s"', e, name) |
| 289 | from pywebio.session import info as session_info |
| 290 | error_msg = '字段内容不合法' if 'zh' in session_info.user_language else 'Your input is not valid' |
| 291 | |
| 292 | if error_msg is not None: |
| 293 | send_msg('update_input', dict(target_name=name, attributes={ |
| 294 | 'valid_status': False, |
| 295 | 'invalid_feedback': error_msg |
| 296 | })) |
| 297 | return False |
| 298 | elif clear_invalid: |
| 299 | send_msg('update_input', dict(target_name=name, attributes={ |
| 300 | 'valid_status': 0, # valid_status为0表示清空valid_status标志 |
| 301 | })) |
| 302 | return True |
| 303 | |
| 304 | |
| 305 | def trigger_onchange(event_data, onchange_funcs): |
no test coverage detected
searching dependent graphs…